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 9082105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:28:37+00:00 2026-06-16T20:28:37+00:00

In java, after creating a button this way: Button button1= new Button(); i can

  • 0

In java, after creating a button this way:

Button button1= new Button();   

i can identify the reference of a button this way

public void actionPerformed(ActionEvent bottonName){            
            Button name_of_the_button= (Button)bottonName.getSource();
                    //Inside 'name_of_the_button' I have 'button1'
}

How can i do the same on android? I tried this way

 public void onClick(View bottonName) {
            Button name_of_the_button= (Button )bottonName.getSource();
}

But on android there isn’t the method getSource().

  • 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-16T20:28:38+00:00Added an answer on June 16, 2026 at 8:28 pm
    Button name_of_the_button = (Button)findViewById(R.id.my_btn);
    

    then

    name_of_the_button.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
    
                if (v.getId() == R.id.my_btn) {
    
                                  // button action here
    
                }
    
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android app I'm creating new WebViews from Java code; however after I
I'm creating a Java application for image processing , and after a while of
Just after creating the new Android Application Project I get the error R cannot
After creating a player by using method this code: player = Manager.createPlayer(getClass().getInputStream(/sound.wav), audio/x-wav) Is
I am new to eclipse and java. The way I understand the directory structure
I am hoping someone can help. Still very new to Android/Java. I have an
After creating a uberjar with leiningen, and running the jar with java -jar foo-uberjar.jar
even after creating new object of unmarshaller every time, threads are getting blocked Please
I can't start eclipse 3.6 helios on ubuntu 10.10 after creating dynamic web project
I've been looking into creating a new application for iOS and after my last

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.