Ids.xml File Examples:
XML file saved at res/values/ids.xml :
How to use:
One:
Two: Button btn=newButton (context); btn. SetId (Context.getresources (). Getinteger (R.ID.BUTTON_OK)); The written form of the red part is incorrect, we use Btn.setid directly (R.ID.BUTTON_OK); OK, If you use the red part, you will be presented with an error that cannot be found. Using both of these methods is possible, if we use ids.xml we have the following several benefits: 1. Naming is convenient, we can put some specific control first name, we use the time directly in our layout to set the ID, save a naming link. 2. When we write the code layout, when we set the ID, we need to use this method to name our control, it can be found in the R file to find the corresponding ID, and then to convert. Note: Each item in Ids.xml will also be generated into the R file, as the above Ids.xml will generate the following control in our R file: public static final class ID {public static final intbutton_ok=0x7f080000;public static final intdialog_exit=0x7f080001;When we use it, no matter which way you set the ID, it is the same: Findviewbyid (R.ID.XXX);
Use of Android Ids.xml resources