What is the difference between @ ID/XX and @ + id/xx when defining the Control id during android page layout?

Source: Internet
Author: User

The component in Android needs to be represented by an int value, which is the id attribute value in the component tag.


The id attribute can only accept the value of the resource type, that is, the value that must begin with @, such as @ id/abc and @ + id/xyz.


If "+" is used after @, it indicates that after a layout file is modified and saved, the system will automatically go to the R. java file.


Generate corresponding int type variables. The variable name is the value after "/". For example, @ + id/xyz is generated in the R. java file.


Int xyz = value, where value is a hexadecimal number. If xyz already has a variable with the same name in R. java,


Instead of generating new variables, the component uses the value of the existing variable.


Since the id attribute of a component is a resource id, you can set any existing resource id values, such as @ drawable/icon,


@ String/OK, @ + string/you, etc. You can also set an existing resource id in the android system, for example, @ id/android: list,


So what does android mean? In fact, android is the package of the system's R class (in the R. java file.


You can enter android. R. id. In the Java code editing area to list the corresponding resource IDs. 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"/>
You can also view the ids defined in the system, go to the <android sdk installation directory> \ platforms \ android-1.5 \ data \ res \ values directory, and find ids. xml file. After opening, 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 ids are defined in ids. xml, @ ID/price_edit can be defined as follows in layout; otherwise, @ + id/price_edit


From [Xiao]

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.