@id and @+id differences in Android

Source: Internet
Author: User

Recently upgraded adt21+, in the output apk encountered compile layout exception, looked at is because someone in layout reference a nonexistent resid when using the @+id/xxx, instead of @id/xxx, cause the debug compiler does not show errors, In the case of a compiler error while packaging, adt21-does not have this problem.

Attached with picture description:

The difference between @id and @+id in Android:

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.

[HTML]View PlainCopy
    1. <span style="FONT-SIZE:14PX;" ><ListView android:id="@+id/android:message"
    2. Android:layout_width="Wrap_content"
    3. android:layout_height="wrap_content"/></span>



There is another way to view the IDs defined in the system and enter

<android SDK installation directory >\platforms\android-1.5\data\res\values directory, locate the Ids.xml file, after opening, the contents are as follows:

[HTML]View PlainCopy
  1. <span style="FONT-SIZE:14PX;" ><? XML version= "1.0" encoding="Utf-8"?>
  2. <resources>
  3. <item type="id" name="Price_edit">false</Item>
  4. <item type="id" name="Amount_edit">false</Item>
  5. </Resources> </span>

Reference Source: http://wenku.baidu.com/view/c6cda2ef856a561252d36ff5.html

If you define an ID in Ids.xml, you can define @id/price_edit in layout as follows, otherwise @+id/price_edit

@id and @+id differences 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.