[android] How do I get the resource id of an image if I know its name?

How do I get the resource id of an image if I know its name (in Android)?

This question is related to android android-image android-resources

The answer is


With something like this:

String mDrawableName = "myappicon";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());

Similar questions with android tag:

Similar questions with android-image tag:

Similar questions with android-resources tag: