8

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

Martyn
  • 16,432
  • 24
  • 71
  • 104
Hammer
  • 8,538
  • 12
  • 44
  • 75

1 Answers1

8

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.

Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98
satur9nine
  • 13,927
  • 5
  • 80
  • 123