android - How does findViewById initialise a view -
i wrote reply confused findviewbyid , realised have gap in understanding. question knowledge , curiosity only.
consider this:
button = (button)findviewbyid(r.id.button);
findviewbyid
returns instance of view
, cast target class. far.
to setup view, findviewbyid
constructs attributeset
parameters in associated xml declaration passes constructor of view
.
we cast view
instance button
.
how attributeset
passed in turn button
constructor?
[edit]
so confused 1 :). whole point when layout inflated, view hierarchy contains instance of view descendant class. findviewbyid returns reference it. obvious when think - doh..
findviewbyid
nothing. looks through view hierarchy , returns reference view requested viewid
. view
created , exists. if not phone call findviewbyid
view nil changes.
views inflated layoutinflator
. when phone call setcontentview
xml layout parsed , view hierarchy created.
attributes passed button's constructor layoutinflater
. check layoutinflator source code.
android
No comments:
Post a Comment