Getidentifier () Get Resources

Source: Internet
Author: User

Use the Getidentifier () method to easily obtain the specified resource ID under each application package.
There are two main ways of doing this:
(1) mode one
Resources resources = Context.getresources ();
int indentify = resources. Getidentifier (Org.loveandroid.androidtest:drawable/icon ", null,null);
if (indentify>0) {
icon = resources.getdrawable (indentify);
}

The first parameter format is: Package name +: + Resource folder name +/+ resource name; Is this format and the other can be null

(2) mode two
Resources resources = Context.getresources ();
Intindentify= getresources (). Getidentifier ("icon", "drawable", "Org.anddev.android.testproject");

The first parameter is the ID name, the second is the resource attribute is the ID or the drawable, and the third is the package name.

Returns the resource ID if found, and returns 0 if it is not found.

Reference URL: http://blog.csdn.net/fengye810130/article/details/9314347

Getidentifier () Get 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.