Reputation: 4324
I was searching for difference in @id/ and @+id/ in our XML layouts. I got another question in my mind, Should we use different name for every component declared in layout for our application ?
I know that we can not declare two components with same name in a layout, But if i talk about entire application. I use same name in other layouts.
Is this the correct way of coding ?
This answer quote that when we declare @+id/ there is new entry in R.java
file, If i add same name component in other layout, Will it create other entry in R.java file ???
I am confused in this, and what is the right way of declaring names in XML layout.
Any help would be appreciated.
Upvotes: 0
Views: 81
Reputation: 823
You should use the different name for each view in your application. And for difference for @id and @+id read the content in the following link you understand better Difference between "@id/" and "@+id/" in Android
Upvotes: 0
Reputation: 317968
If you use @+id notation in multiple places, it will not create a new ID value each time it's used. The compiler will reuse the same ID for each of the same name in the same app.
You can use the @id notation when you know you are referencing an existing id. This is common when using relative layouts where you want to align some view with another view of some id in the same layout.
Upvotes: 2