difference between these three Buttons “Button button = (Button)” [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



difference between these three Buttons “Button button = (Button)” [closed]



What is the difference between these three Buttons


Button button = (Button)



I mean to say what is 1st button and what is 2nd button and also what is 3rd button? I cant find the explanation on the internet, every one in the video lecture uses these three "button", I am totally confused with these buttons. And also


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



Why are they using R? Could someone just give me explanation on this line of code to better understand? please help me, Thanks in Advance


R



enter image description here



This question appears to be off-topic. The users who voted to close gave this specific reason:





So I'm guessing you really need to go through The Java Tutorials and learn the basics of the language
– scrappedcola
Aug 10 at 21:38






Post the code as text, not as image.
– scopchanov
Aug 11 at 1:24





I think now first i have to understand JAVA first, and than i will go further, thanks for answer.
– SYED ASAD ABBAS
Aug 11 at 10:57




2 Answers
2



Oh, guy, it's a root things, if you don't know how to declare variables, it will be difficult for you. My advice try to read obout java core first.
In few words, Button from Capital letter is a declaration of variable type, next button is the name of the variable, (button) you can easily delete it. Rshows on the resourses of your app.


Button


button


(button)


R





I think now first i have to understand JAVA first, and than i will go further, thanks for answer.
– SYED ASAD ABBAS
Aug 11 at 10:58





Thx, for accept an answer. I can recommend you link i started with it half a year ago, very good basic free cources.
– Stanislav Batura
Aug 11 at 17:00



You need to take a basic Java class before you dig any deeper. Here is a quick explanation of what you have asked:


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



The first Button is the name of the class. The second button is a reference to an object that you are going to get by calling findViewById. This reference can be anything you want. The same line could have been written as


Button


button


findViewById


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



and it would still be valid Java code. You just need to make sure that you use myObjRef from that point onward in your method.


myObjRef



The third Button (on the right of the = sign) is a type cast. This is a more complex concept and you really need to understand other things before you get to this level. Type cast tells the compiler you know what you are doing, and the object being returned by findViewById is of compatible type, even if not really of type Button.


Button


=


findViewById


Button



Finally, in R.id.button, R is the name of a class. It's Android specific.


R.id.button


R





I think now first i have to understand JAVA first, and than i will go further, thanks for answer.
– SYED ASAD ABBAS
Aug 11 at 10:57

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard