The difference between @+id and @id in Android

Source: Internet
Author: User

Components in Android need to be represented by a value of type int, which is the value of the id attribute in the component tag. The id attribute can only accept values of the resource type, which is the value that must begin with @, for example, @id/abc, @+id/xyz, and so on.
Using "+" after @ means that when a layout file has been modified and saved, the corresponding int type variable is automatically generated in the R.java file. The variable name is the value after "/", for example, @+id/xyz generates int xyz = value in the R.java file, where value is a hexadecimal number. If XYZ already has a variable of the same name in R.java, no new variable is generated, and the component uses the value of the existing variable.
That is, if you use the @+id/name form, the component uses the value of the variable as its identity when there is a variable named name in R.java. If the variable does not exist, a new variable is added and the corresponding value is assigned to the variable (no duplicates).
Since the ID property of a component is a resource ID, you can naturally set any resource ID values that already exist, such as @drawable/icon, @string/ok, @+string/you, and so on. Of course, you can also set the existing resource ID on the Android system, for example, the landlord proposed @id/android:list, then what does this Android mean, actually, This android is the package that the system's R class (in the R.java file) resides in. We can enter android.r.id in the Java Code Editor, and the corresponding resource ID will be listed, for example, you can also set the ID property value to @id/android:message. <listview android:id= "@+id/android:message" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"/>
There is another way to view the ID defined in the system and go to the <android SDK installation
>\platforms\android-1.5\data\res\values directory, find the Ids.xml file, open, the content is as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <resources>
<item type= "id" name= "price_edit" >false</item> <item type= "id" name= "amount_edit" >false</item > </resources>
If you define an ID in Ids.xml, you can define @id/price_edit in layout as follows, otherwise @+id/price_edit

The difference between @+id and @id in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.