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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:49:44+00:00 2026-06-05T09:49:44+00:00

Possible Duplicate: Java this.method() vs method() I’ve been reading some things and doing some

  • 0

Possible Duplicate:
Java this.method() vs method()

I’ve been reading some things and doing some tutorials about android java but I still dont understand what “this” means, like in the following code.

    View continueButton = this.findViewById(R.id.continue_button);
    continueButton.setOnClickListener(this);
    View newButton = this.findViewById(R.id.new_button);
    newButton.setOnClickListener(this);

Also why is it in this example that a button is not defined with Button but with View, what is the difference?

ps. Great site!! trying to learn java and got ALLOT of answers by searching here!

  • 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-05T09:49:45+00:00Added an answer on June 5, 2026 at 9:49 am

    The this keyword is a reference to the current object. It is used to pass this instance of the object, and more.

    For example, these two allocations are equal:

    class Test{
    
        int a;
    
        public Test(){
            a = 5;
            this.a = 5;
        }
    
    }
    

    Sometimes you have a hidden field you want to access:

    class Test{
    
        int a;
    
        public Test(int a){
            this.a = a;
        }
    
    }
    

    Here you assigned the field a with the value in the parameter a.

    The this keyword works the same way with methods. Again, these two are the same:

    this.findViewById(R.id.myid);
    findViewById(R.id.myid);
    

    Finally, say you have a class MyObject that has a method which takes a MyObject parameter:

    class MyObject{
    
        public static void myMethod(MyObject object){
            //Do something
        }
    
        public MyObject(){
            myMethod(this);
        }
    
    }
    

    In this last example you passed a reference of the current object to a static method.

    Also why is it in this example that a button is not defined with Button but with View, what is the difference?

    In Android SDK, a Button is a subclass of View. You can request the Button as a View and cast the View to a Button:

    Button newButton = (Button) this.findViewById(R.id.new_button);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is the ellipsis (…) for in this method signature? java: how
Possible Duplicate: Max name length of variable or method in Java I was reading
Possible Duplicate: what is wrong with this call to the java method? The following
Possible Duplicate: Plugging in to Java compilers Edit - this appears to be a
Possible Duplicate: Java operator overload In c++, we can perform the operator overloading. But
Possible Duplicate: Platform independent paths in Java I make a program but it save
Possible Duplicate: Java - why no return type based method overloading? The compiler does
Possible Duplicate: Java GUI repaint() problem? I write a Java code, but I have
Possible Duplicate: Why won't this generic java code compile? Given the following code: import
Possible Duplicate: Calling a method named “string” at runtime in Java and C I

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.