Android examples for App:Resource
get Id Resource
//package com.java2s; import android.content.Context; public class Main { public static int getIdResource(Context ctx, String name) { String packageName = ctx.getPackageName(); try {//w ww . j a va 2 s.c o m Object obj; obj = Class.forName(packageName + ".R$id").newInstance(); return Class.forName(packageName + ".R$id") .getDeclaredField(name).getInt(obj); } catch (Exception e) { e.printStackTrace(); return 0; } } }