This documentation always puzzles me:
For the ID value, you should usually use this syntax form: "@+id/name". The plus symbol, +, indicates that this is a new resource ID and the aapt tool will create a new resource integer in the R.java class, if it doesn't already exist. For example:
<TextView android:id="@+id/nameTextbox"/>
I've been programming for quite a while now. However, I've never encountered any case wherein I have to use the ID declaration without the plus sign. It is also counter-intuitive. IDs are supposed to be unique!
Any good use-case for this? Why would one want to re-use the same resource id name?
@+id/name When you create a new id
"@id/" When you link to existing id
Use-case example 1:
Let's say you created your own resource in XML:
<resources>
<item name="plusIcon" type="id"/>
</resources>
Now you can use this resource at multiple places without creating a new resource using @+id. Say layout_one.xml
:
<TextView android:id="@id/plusIcon"/>
Same resource in layout_two.xml
:
<TextView android:id="@id/plusIcon"/>
Use-case example 2:
There are a number of other ID resources that are offered by the Android framework. If you want to referencing an Android resource ID in that case you can use @android you don't need to create your own new resource ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With