What is the use of findViewById in Android?
Also know, what is findViewById?
R is a Class in android that are having the id's of all the view's. findViewById is a method that finds the view from the layout resource file that are attached with current Activity.
Similarly one may ask, what are views in Android?
View is a basic building block of UI (User Interface) in android. A view is a small rectangular box which responds to user inputs. Eg: EditText , Button , CheckBox , etc.. ViewGroup is a invisible container of other views (child views) and other viewgroups.
As mentioned by @Jon Skeet in comments, findViewById(int id) method returns view(not subviews) in general, but this method is generic and can returns subviews if the compiler knows the type of target class, so in this case, casting is redundant, but in the case that, the type of target class is unconstrained, you have