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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With