I just wrote an answer for someone confused by findViewById, and I realized that I have a gap in my understanding. This question only concerns knowledge and curiosity.
Consider this:
button = (Button)findViewById(R.id.button);
findViewById returns an instance of View , which is then discarded to the target class. All is good so far.
To customize the view, findViewById creates an AttributeSet from the parameters of the associated XML declaration that is passed to the View constructor.
Then we apply the View instance to the Button .
How to pass AttributeSet in turn to Button constructor?
[EDIT]
So I was confused :). The thing is that when the layout is inflated, the view hierarchy already contains an instance of the view child class. findViewById just returns a link to it. Obviously, when you think about it - doh ..
android
Simon Feb 10 '13 at 18:22 2013-02-10 18:22
source share