-1

I am a little confused about findviewbyid. Just wanna to give a brief explanation and if any mistakes please review them.

    class test
   { 
     Button btes;
     public void OnCreate(Bundle savedIntasnceState);
     super.OnCreate(savedInstanceState);
     btes = (Button)findViewById(R.id.button);

   }

Does this mean that findViewById returns a reference to View object and instance of Android.Widget.Button. Android.widget.button extends findViewById.

Questions: 1. Is the above statement correct. If not then what is the correct statement. 2. Can anyone provide the source code of findViewById function of the view class 3. What are those hexadecimal numbers in R.java.

  • 1
    There is no need to ask definition of a method in SO. you can go to [developer.android.com](https://developer.android.com/reference/android/app/Activity.html#findViewById(int)) to learn those. Also you can press ctrl + right click on the method to see method implementation and definition in Android Studio. – Blasanka Jul 16 '17 at 04:09

1 Answers1

0

1a. No the statement you said was incorrect, the correct version would be the following:

findViewById(R.id.button) is a method which is used to find views that you set in your XML with the tag android:id; (button) is type casting the return value into a button object

1b. Button extends Textview which extends View

2. See below

3. Please clarify what you mean (add a comment to your question)

Learn more about findViewById here

Learn more about type casting here

Seabass77
  • 187
  • 5
  • 13
  • thank you for your answer,I had a doubt,typecasting for button can be done only if the return object is instantiated from button class which extends view class. example ; View something = new Button(); – Abhishek Chauhan Jul 16 '17 at 05:20
  • Well if you were to do the following: View foo = new Button(); you would be **Downcasting or Narrowing Reference Conversion** since the Button class extends TextView which extends View. Essentially slicing a bunch of extra data (all of the stuff that makes a button a button) off until you are left with just a View. You should check this [post](https://stackoverflow.com/a/20097325/3843432) for more information on type casting. – Seabass77 Jul 16 '17 at 05:39