Use of Android Ids.xml resources

Source: Internet
Author: User

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

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.