Hi
after the listing comes an explanation Accessing view objects by ID
Can anybody explain it in his own words - didn’t understand the text
Hi
after the listing comes an explanation Accessing view objects by ID
Can anybody explain it in his own words - didn’t understand the text
Hey Hothcoder
In the layout file (activity_main.xml) you have two buttons with corresponding ids that identifies them.
For the true button the id is
<Button android:id="@+id/true_button".
You access the button using findViewById.
As the name implies it looks for and finds the button in the layout file.
R is a generated class that means Resource. So, as you might have guessed it is a class that has access to all the resources in your project and widgets like buttons in layout files.
Okay. When you say findViewById(R.id.true_button) you are asking the function to get you the resource with that id.
Thank you for this clear explanation.