FYI Views in Android cannot be shared, this is a debatable sdk design decision, but thats the way it is. Each view can have at most one parent view. However in order for a layout to serve as a view template, a common view_layout.xml file can be reused (ie inflated several times). What are the implications for the viewid and the id of elements within the view such as buttons.
- Should these not be defined inside the view_layout.xml? (eg so that there are not for example two buttons with the same id albeit in different view instances).
- what about the instance id of the view itself?
- How are these views to be uniquely defined given the common view_layout.xml file?
- Of course you can have separate references to the views inflated but what about the id of the view itself and the widgets inside it?
I’m not sure what exactly you are trying to address here, but Views in a layout should never clash if you designed your layouts properly. View Ids apply only to the direct parent ViewGroup. Suppose you have ViewGroup A and it is your top level ViewGroup. You then inflate two instances of ViewGroup B and add then to A, their respective Ids will not clash as they have no reference of eachother. Their scopes are completely different.