Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.res.Resources; public class Main { public static int getResIdByName(Context context, String resName) { Resources res = context.getResources(); final String packageName = context.getPackageName(); int imageResId = res.getIdentifier(resName, "drawable", packageName); return imageResId; } }