In each android project there is a gen
folder inside src
where R.java
is created automatically and all the IDs of resources used/created in XMLs belong here.
As the docs say:
The at sign (@) is required when you're referring to any resource object from XML.
This means that you are going to refer an ID from R.java
if you add +
then the corresponding id will be created if it does not exists in R.java
already. As the docs say:
The plus sign (+) before the resource type is needed only when you're defining a resource ID for the first time. When you compile the app, the SDK tools use the ID name to create a new resource ID in your project's gen/R.java
file that refers to the EditText
element. With the resource ID declared once this way, other references to the ID do not need the plus sign.
So +
sign is required only when you want to create a new id for the view. If it is already created in the same file then it will simply reuse that id instead of creating a new id with the same name.
NOTE: you can use +
with IDs only.
@
has so many uses. The one which are used mostly are:
@id/
to reference from R.id
@string/
references R.string
similarly...
@drawable/
-> R.drawable
@array/
-> R.array
@color/
-> R.color
Finally you can use @android
to refer resources defined in the android SDK.