Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between View.findViewById() and Activity.findViewById()?

Tags:

android

I am new to android programming i have confusion between View.findViewById() and Activity.findViewById(), when do we have to call these methods and in which class findViewById() method resides i.e in View class or Activity class.

Any help will be appreciated.

like image 463
user3387084 Avatar asked Apr 22 '15 20:04

user3387084


1 Answers

The View version searches the view you call it on and all subviews of it. The Activity one searches the top level view set in setContentView and all subviews of it. The Activity one is equivalent to calling View.findViewById on the contentView of the activity.

Its basically a convenience method to make it easier to search for an id within all the views of an activity without having to remember what the top view in it is.

like image 174
Gabe Sechan Avatar answered Oct 19 '22 17:10

Gabe Sechan