What Is @ In "@+id/idname" Format Mean In Android?
Solution 1:
If the ID is not already created, then +
will create it. You will need it only the first time you refer to that id.
From docs :
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.
Like the docs say, the @
symbol means you are referring to an xml resource.
For example : @string/edit_message
means you are trying to refer to a string with the id edit_message defined in an xml file.
Solution 2:
@ sign
means you are referring to a resource
under res folder.
@drawable
refer to a .png or button state images.
@anim
refer to animation
@id/anyID
refer to any pre Created id
@+id/createNewID
+ create a new id and name it createNewID and
+sign only works with id. you cannot use it with anim,drawable.
Note
You can not create any Resource programatically other than id.
Solution 3:
@ is used to give identity or to refer to the existing resource in XML File.
'@' specifies what kind of resource you are about to access. if you use @id, it will refer to any resources in layout of project. if you use @string, it will locate to a string that you may usually specify in Strings.XML
there are so many other resources like : @drawable, @color, @style, @array, @dimen, @layout & @xml..
you can use according to your requirement.
Solution 4:
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 theEditText
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 fromR.id
@string/
referencesR.string
similarly...@drawable/
->R.drawable
@array/
->R.array
@color/
->R.color
Finally you can use @android
to refer resources defined in the android SDK.
Post a Comment for "What Is @ In "@+id/idname" Format Mean In Android?"