The difference analysis of @id and @+id in Android programming _android

Source: Internet
Author: User

This paper analyzes the difference between @id and @+id in Android programming. Share to everyone for your reference, specific as follows:

Components in Android need to be represented by a value of type int, which is the value of the id attribute in the component label.

The id attribute can only accept values for resource types, that is, values that must begin with a @, such as @id/abc, @+id/xyz, and so on.

If you use "+" after the @, it means that when a layout file is modified and saved, the system automatically generates the corresponding int type variable 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, the new variable is not generated, and the component uses the value of the existing variable.

Since the component ID attribute is a resource ID, you can naturally set any existing resource ID values, such as @drawable/icon, @string/ok, @+string/you, and so on. You can also set a resource ID that already exists in the Android system, such as @id/android:list, so what does this Android mean, in fact, this Android is the package of the system's R class (in R.java file).

We can enter android.r.id in the Java Code editing area, and the corresponding resource IDs are listed, for example, or you can set the ID property value to @id/android:message.

There is another way to view the ID defined in the system, into the Sdk/platforms/android-16/data/res/values directory, ids.xml file;

<?xml version= "1.0" encoding= "Utf-8"?> <!--* * * * Copyright 2007, the Android Open Source Project * * * Licensed
Under the Apache License, Version 2.0 (the "License");
* * may not use this file except in compliance with the License. * * Obtain a copy of the License at * * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * unless required by app Licable or agreed to in writing, software * * Distributed under the License is distributed on ' as is ' basis, * * with
Out warranties or CONDITIONS of any KIND, either express OR implied.
* * The License for the specific language governing permissions and * * Limitations under the License. */--> <resources> <item type= "id" name= "background"/> <item "type=" id "name=" checkbox "/> <ite M type= "id" name= "content"/> <item type= "id" name= "empty"/> <item "type=" id "name=" hint "/> <item ty Pe= "id" name= "icon"/> <item type= "id" name= "icon1"/> <item, type= "id" name= "ICon2 "/> <item type= id" name= "input"/> <item type= "id" name= "left_icon"/> <item type= "id" name= "li St "/> <item type=" id "name=" menu "/> <item" type= "id" name= "message"/> <item type= "id" name= "primary "/> <item type=" id "name=" progress "/> <item type=" id "name=" right_icon "/> <item type=" id "name=" su  Mmary "/> <item type= id" name= "selectedicon"/> <item "id" type= "name=" tabcontent/> "id" Name= "Tabhost"/> <item type= "id" name= "tabs"/> "<item" type= "id" name= "text1"/> <item "id" nam E= ' Text2 '/> <item type= ' id ' name= ' title '/> <item ' type= ' id ' name= ' title_container '/> <item ' type= ' ID "Name=" Toggle "/> <item type=" id "name=" secondaryprogress "/> <item" type= "id" name= "lock_screen"/>
 Item type= "id" name= "edit"/> <item type= "id" name= "widget_frame"/> <item "id" type= "name=" button1 <item type= "id" name="Button2"/> <item type= "id" name= "button3"/> "<item" type= "id" name= "extractarea"/> <item type= "id" Name= "Candidatesarea"/> <item type= "id" name= "inputarea"/> <item "id" type= "name=" Inputextractedittext
 Gt <item type= "id" name= "selectall"/> <item type= "id" name= "cut"/> <item "id" type= "copy" Name= < 
 Item type= "id" name= "paste"/> <item type= "id" name= "copyurl"/> <item type= "id" name= "selecttextmode"/> <item type= "id" name= "switchinputmethod"/> <item "id" type= "name=" Keyboardview/> "id" name = "CloseButton"/> <item type= "id" name= "startselectingtext"/> "<item" type= "id" name= "stopselectingtext"/&G
 T <item type= "id" name= "addtodictionary"/> <item type= "id" name= "accountpreferences"/> <item "id" NA Me= ' SmallIcon '/> <item type= ' id ' name= ' custom '/> <item ' type= ' id ' name= ' home '/> <item ' id ' nam E= "Fillinintent"/> <item type= ' id ' name= ' rowtypeid '/> <item ' type= ' id ' name= ' up '/> <item ' type= ' id ' name= ' action_menu 
 _divider "/> <item type= id" name= "icon_menu_presenter"/> <item "id" type= "name=" List_menu_presenter  <item type= "id" name= "action_menu_presenter"/> <item "id" type= "name=" Overflow_menu_presenter/>

 Type= "id" name= "popup_submenu_presenter"/> </resources>

If the ID is defined in the Ids.xml, then the layout can be defined as @id/price_edit or @+id/price_edit;

In simple terms:

@+id a new resource ID
@id and Android:id, referencing an existing resource ID

I hope this article will help you with the Android program.

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.