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

  • SEARCH
  • Home
  • 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 6616121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:32:42+00:00 2026-05-25T20:32:42+00:00

Alright, so i’ve been making great progress on the app i’m trying to create,

  • 0

Alright, so i’ve been making great progress on the app i’m trying to create, but most of the tutorials that i’ve been learning from only showcase the wondrous feature of having only one active widget inside the application at a time…

The thing is, my application requires 2 or more buttons and that’s the part i’m partially stuck at. My code implements a "SetWordsBtn" shown below (everything else is declared),

public void onCreate(Bundle icicle) {

   super.onCreate(icicle);
   setContentView(R.layout.main);

   SetWordsBtn=(Button)findViewById(R.id.SetWordsBtn);

   SetWordsBtn.setOnClickListener(this);

}

which implements a onClick() like this:

public void onClick(View view) {

  startWords();

}

but what if i have another button that deletes the words such as "DelWordsBtn"? I was thinking i could declare both buttons simultaneously like this:

  SetWordsBtn=(Button)findViewById(R.id.SetWordsBtn);
  DelWordsBtn=(Button)findViewById(R.id.DelWordsBtn);

  SetWordsBtn.setOnClickListener(this);
  DelWordsBtn.setOnClickListener(this);

but what about the onClick() method? Does it automatically apply itself to both the buttons when i do this?

How am i able to declare a seperate onClick from each other so it both does different stuff when i click on either one of them?

I was thinking the answer could be something like this, but i dunno :

  //Declarations
  SetWordsBtn=(Button)findViewById(R.id.SetWordsBtn);
  DelWordsBtn=(Button)findViewById(R.id.DelWordsBtn);

  SetWordsBtn.setOnClickListener(setWordsView);
  DelWordsBtn.setOnClickListener(delWordsView);

  //onClick Functions

public void onClick(View setWordsView) {

  startWords();

}

public void onClick(View delWordsView) {

  deleteWords();

}

So it would actually link the startWords() function to the SetWordsBtn, and deleteWords() to DelWordsBtn…

Any clear cut explanation/form of help would be appreciated. Thanks in advance guys. 🙂

  • 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-05-25T20:32:42+00:00Added an answer on May 25, 2026 at 8:32 pm

    The typical convention is to just switch off of the ID of the View that is clicked. For example:

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch(v.getId()) {
                case R.id.SetWordsBtn:
                    startWords();
                    break;
                case R.id.DelWordsBtn:
                    deleteWords();
                    break;
            }
        }
    };
    
    int[] ids = { R.id.SetWordsBtn, R.id.DelWordsBtn };
    
    for(int i : ids) ((Button)findViewById(i)).setOnClickListener(listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, so I've been trying to implement a simple binary search tree that uses
Alright, I'm trying to read a comma delimited file and then put that into
Alright so i have been working on this Dynamic load of a spinner from
Alright, I'm trying to use the basic document.getElementsByTagName function, but each time I do,
Alright I am trying to set up an OAuth Provider in PHP, but I
Alright, here we go! I am currently developing an iPhone app that will work
Alright, I am trying to accomplish this: When a user clicks a button that
Alright, so I'm trying to add a slash screen to my app to facilitate
Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis

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.