Give your drawables the Names of the text you are matching like A.png for apple.
Then, use the below to get its id from name
public int getID(String drawableName){
Resources resources = context.getResources();
final int resourceId = resources.getIdentifier(drawableName, "drawable",
context.getPackageName());
return resources.getDrawable(resourceId);
}
and simply do,
tv.setDrawableLeft(getID(tv.getText.toString()));
Hope this helps. (I like @0xDEADC0DE answers as well. :))