Q:

How can I get a resource by name based on a string variable?

I want to  do
String childImg = "childIcon";
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.????, 0, 0, 0);

it's expecting an int but i have a string. how do i work around this?

A:

I use this to get drawable id
getResources().getIdentifier(childImg, "drawable", getPackageName())

