I want to access a resource like a String or a Drawable by its name and not its int id.
Which method would I use for this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It will be something like:
R.drawable.resourcenameMake sure you don’t have the
Android.Rnamespace imported as it can confuse Eclipse (if that’s what you’re using).If that doesn’t work, you can always use a context’s
getResourcesmethod …Where
this.contextis intialised as anActivity,Serviceor any otherContextsubclass.Update:
If it’s the name you want, the
Resourcesclass (returned bygetResources()) has agetResourceName(int)method, and agetResourceTypeName(int)?Update 2:
The
Resourcesclass has this method:Which returns the integer of the specified resource name, type & package.