Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:14:45+00:00 2026-06-15T18:14:45+00:00

I want to make an application with 9 buttons for android 4.0, I need

  • 0

I want to make an application with 9 buttons for android 4.0, I need each of the buttons to call a method when pressed and another method when released.

I’m kind of surprised there’s not a really straight-forward method to accomplish what I just described but thanks to some questions and answers I read on stackoverflow I managed to accomplish what I need by adding a listener in each of the buttons, as shown for one of the buttons in the next code.

buttonUp.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
            buttonUpPressed();
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
            buttonUpReleased();
        }                
        return true;
    }           
});

I want to know if there’s an alternative to accomplish this behavior without having to add a listener for every button. I see that as a waste of resources and a lot of coding. I can’t imagine if I eventually have to add more buttons.

So any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:14:47+00:00Added an answer on June 15, 2026 at 6:14 pm

    implements your class with OnTouchListener

    Button a,b;
            Button[] bArray = {a,b};
            for (int i = 0; i < bArray.length; i++) {
                bArray[i].setOnTouchListener(this)
            }
    

    after that add unimplemented method

    @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
                if(event.getAction() == MotionEvent.ACTION_DOWN){
                    switch (v.getId()) {
                    case R.id.button1:
    
                        break;
    
                    default:
                        break;
                    }
                }
                else if(event.getAction() == MotionEvent.ACTION_UP){
                    switch (v.getId()) {
                    case R.id.button1:
    
                        break;
    
                    default:
                        break;
                    }
                }
            return false;
        }
    

    i hope you’ll like my logic 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make the application like below. First there is a page with
I want to make application that when press the button it will make each
in my android application I want to copy file from one directory to another
I need help! :-) I have an application and want to make it modular,
I want to make a native Android application for a website. The first problem
I am new in Android. I want to make one Audio Recording application. In
I'm building a radio application on android , I want know how to make
I need to make a shared folder in android. I want to be able
I want to create two new custom buttons to use in my android application.
Hi I want to make a custom dialogue box for my android application and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.