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?
It will be something like:
Make sure you don't have the
Android.R namespace imported as it can confuse Eclipse (if thats what you're using).
If that doesn't work, you can always use a context's
getResources method ...
Drawable resImg = this.context.getResources().getDrawable(R.drawable.resource);
this.context is intialised as an
Service or any other
If it's the name you want, the
Resources class (returned by
getResources()) has a
getResourceName(int) method, and a
Resources class has this method:
public int getIdentifier (String name, String defType, String defPackage)
Which returns the integer of the specified resource name, type & package.