Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between findViewById(R.id.content) and getRootView() [closed]

Tags:

android

view

root

What is the difference between findViewById(R.id.content) and getRootView() ? Don't both return the root view of an activity?

like image 683
Hammer Avatar asked May 19 '12 19:05

Hammer


People also ask

What is findViewById () method used for?

FindViewById(Int32)Finds a view that was identified by the android:id XML attribute that was processed in #onCreate .

What is r ID content?

The android. R. id. content ID value indicates the ViewGroup of the entire content area of an Activity .

What does findViewById return?

findViewById returns an instance of View , which is then cast to the target class. All good so far. To setup the view, findViewById constructs an AttributeSet from the parameters in the associated XML declaration which it passes to the constructor of View . We then cast the View instance to Button .

What is Viewview findViewById?

The findViewById() method is a method of Android's View and Activity classes. The method is used to find an existing view in your XML layout by its android:id attribute.


1 Answers

The method findViewById(R.id.content) searches down the view hierarchy for a View with the id content (it examines itself as well).

The method getRootView() walks up view hierarchy until it hits the root View (it examines itself as well).

If the View you are in has the id content and it is the root view then these methods will give the same result, otherwise they won't.

like image 105
satur9nine Avatar answered Sep 19 '22 11:09

satur9nine