How does android use R.id.id_name to find views after inflating the XML?
1.Suppose I have two XML’s with one button each with same id.
2.I have inflated them and converted them into views
3.In R.id class only one int will be created for both the buttons.
How does android differentiate these buttons with same id Using same Resource name(R.id.id_name) .
The ID is not a unique reference.
However, in practice, you differentiate by using the parent view.
If we consider that ‘this’ is an Activity, set up with a layout that contains your buttons, then:
will return the first one it finds in the layout (I think – not sure the actual behaviour is defined).
However what you might do is call
findViewByIdon some parent view that contains only one such instance with that ID.Conceptually, this is a sort of path based lookup. You should be careful to design your layouts such that this is possible.