We all know that when generating an id for Android using
@+id/foo
Android creates for us an entry in R.java like:
public static final class id {
public static final int foo=0x7f060005;
}
What happens if there is a name collision in different xml files (let’s say, inside two layouts)? The @+id mechanism ensures us to overwrite the id name if another one still exist, but which one is generated in R.java for us?
The
@+id/foosyntax will add if the id doesn’t exist or use the existing id.When you findViewById, it will operate on the view on which you call the method.
So, if you have nested Views, your id will be unique for each view.
e.g. View1 -> View2 both have foo.
View1.findViewById(R.id.foo)will be different fromView2.findViewById(R.id.foo)edit: I guess the main thing to mention is that two layouts can’t have the same id.
For more information on the id constraint: http://d.android.com/guide/topics/ui/declaring-layout.html