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

manu picture manu · Jun 15, 2010 · Viewed 100.8k times · Source

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

Answer

Francesco Laurita picture Francesco Laurita · Jun 15, 2010

With something like this:

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