Q:

How to select a drawable image by matching a string value to the image name? 

I have an arraylist of strings, I need to randomly select an index and if the string value was 
"bear", then set background of button to bear.jpg. 
OK, my research shows that resources are accessed by an int id, not their name, I am not sure the best way to achieve what I want to do.  Here is my code:
    list.add("alligator");
    list.add("bear");
    list.add("beaver");
    list.add("bison");

    randomInt = randomGenerator.nextInt(list.size());
    b1.setBackgroundResource(R.drawable.list.get(randomInt));

Now of course the last line of the code is wrong, I wrote it to show what I want to achieve.  My latest attempt to accomplish this was trying to get the resource id and access the resource this way, but I don't know if this is the way to do this, and if it is I am not using the correct code.  I am trying hard to do this by myself but I could use some advice on what to do here.  Here is my attempt:
         String mDrawableName = "bear";
         int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());

        String s= Integer.toString(resID);

A:

Use the below code
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());    
b1.setBackgroundResource(resID);

