-1

I am doing this course on Coursera, and in the 3rd week 1st block video, the instructor has us write the following line of code:

buttonBlue = (Button) findViewById(R.id.buttonInvisibleMan);

What is the significance of each part of this line of code? What does the R.id. stand for? What is the importance of the "(Button)"?

Please explain each part in detail.

Thank you

  • This site is not exactly a wiki, there are another questions related to findViewById like [this](https://stackoverflow.com/questions/35357734/how-does-findviewbyid-work) try to do your own research and if then there are some doubts, make a specific question. – javdromero Apr 27 '21 at 14:04
  • 1
    This really just requires some of your own research. For some hints, you want to research what `R` is specifically in Android and what a cast is in Java. But I think that a beginners Java tutorial would be a good place to start before your course. Without some background knowledge you're going to struggle. – Henry Twist Apr 27 '21 at 14:06

1 Answers1

0

R.id. stands for the Resource ID which is important because blueButton needs to know which UI element it needs to work with.

(Button) is a form of casting, by writing (Button) you promise the compiler that this will be a Button element and not TextView or any other UI element.

Dharman
  • 30,962
  • 25
  • 85
  • 135