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. This value is the id attribute value in the component label.

The id attribute can only accept values of the resource type, which is the value that must begin with @, such as @id/abc, @+id/xyz, and so on.
Suppose that "+" is used after the @, indicating that when a layout file has been modified and saved, the system will voluntarily generate the corresponding int type variable in the R.java file itself. The variable name is the value after "/". For example, @+id/xyz will generate int xyz = value in the R.java file. Where value is a hexadecimal number. Assuming that XYZ already has a variable of the same name in R.java, no new variables are generated. The component will use the value of this existing variable.
That is, assuming that the @+id/name form is used, the component uses the value of the variable as its identity when there is a variable named name in R.java. Assume that the variable does not exist. A new variable is added. and assigns a corresponding value to the variable (not repeated).
Since the id attribute of the component is a resource ID, it is natural to set the resource ID value regardless of what already exists, such as @drawable/icon, @string/ok, @+string/you, and so on. Of course, you can also set a resource ID that already exists in the Android system, for example. The landlord put forward the @id/android:list. So what does this Android mean, actually. This android is the package of the system's R class (in the R.java file). We are able to enter android.r.id in the Java Code editing area, and the corresponding resource ID is listed. For example, you can also set the id attribute value to @id/android:message. <listview android:id= "@+id/android:message" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"/>
There is a second way to view the ID defined in the system and go to the <android SDK installation
Record >\platforms\android-1.5\data\res\values folder. Locate the Ids.xml file. When opened, the contents are 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 the ID is defined in Ids.xml. You can define @id/price_edit for example in layout, otherwise @+id/price_edit


To summarize:

One, android:id= "@android: Id/tabhost" is called inside the system ID and code

Mtabcontent = (framelayout) Findviewbyid (com.android.internal.r.id.tabcontent);

Second, android:id= "@+id/llroot" is to customize a new ID.

Android:id= "@id/llroot" uses an already existing ID number reference ( unlike the first one, which is not the system referenced here )


The difference between @+id and @id in Android

Related Article

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.