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