Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int getDrawableResourceByName(Context context, String resourceName) { int result = -1; result = context.getResources().getIdentifier( resourceName.toLowerCase().replaceAll(" ", "").replaceAll(".png", ""), "drawable", context.getPackageName()); return result; } }