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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:42:33+00:00 2026-06-06T10:42:33+00:00

I have a pretty crappy book so I am not sure for their reasoning

  • 0

I have a pretty crappy book so I am not sure for their reasoning for using either form.

The first way that it would go about it would be like this

 Button button = (Button) findViewById(R.id.btnButton)

 button.setOnClickListener(new OnClickListener() {
//code code code }

Then our book wants to use Global Variables instead of local, so it randomly starts using a different way to go about things

Button btButton;
//Done as Global Variable.

btButton = (Button) findViewById(R.id.btnButton);
btButton.setOnClickListener(bButton);


Button.OnClickListener bButton = new Button.OnClickListener(){
//code }

It is things like this that my book is horrible at and one reason why I will not be buying the next installment of it. I hate when it just changes the way it does things without any real reason. So can anyone really tell me the difference here? Thanks.

  • 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-06T10:42:34+00:00Added an answer on June 6, 2026 at 10:42 am

    As everyone says, there is no difference– but nobody has explained why.

    Button extends View.

    When you are using onClickListener, you are using the one defined in View. Almost always, this one will work– it won’t with Dialogs, and maybe some other classes.

    If you explicitly say Button.onClickListener, you are referencing the onClickListener defined in the Button class, and since Button extends View, this is the same as using the generic onClickListener.

    There is also the inner anonymous vs explicit, but this is more of a preference. You will get better performance using a static onClickListener than in inner anonymous, simply because there is less garbage collection necessary, but you won’t notice it unless you have 30 or so anonymous inner listeners.

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

Sidebar

Related Questions

I have pretty standard Qmail toaster installation. I'm using the dot files to set
Basically I do have pretty simple database that I'd like to index with Lucene.
We have pretty much C# 2.0 code that heavily relies on System.Drawing namespace. Also
I have pretty sophisticated build using gradle - with a number of own gradle
I'm using .htaccess (mod rewrite) to have pretty looking SEO friendly URLs. I have
I have pretty much finished my first WPF project after several weeks. Now I
I have pretty large file names that follow a standard naming practice and I
I have pretty much finished my first working Symbian application, but in my hastened
I have pretty good function that do what I need, but in IE it
Im currently using Code Igniter to have pretty URLs, and I have this system

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.