Android examples for App:Resource
get Layout Name from Resource
//package com.java2s; import java.lang.reflect.Field; import java.util.HashMap; import android.content.Context; import android.content.res.Resources; import android.util.SparseArray; public class Main { private static HashMap<String, Integer> layoutIds; private static SparseArray<String> layoutNames; public static String getLayoutName(Context ctx, Resources res, int id) throws Exception { if (layoutIds == null || layoutNames == null) { HashMap<String, Integer> map = new HashMap<String, Integer>(); SparseArray<String> map2 = new SparseArray<String>(); String rClazz = ctx.getPackageName() + ".R.layout"; Class<?> r = ctx.getClassLoader().loadClass(rClazz); for (Field f : r.getDeclaredFields()) { if (java.lang.reflect.Modifier.isStatic(f.getModifiers()) && f.getType() == Integer.TYPE) { Integer val = (Integer) f.get(null); map.put(f.getName(), val.intValue()); map2.put(val.intValue(), f.getName()); }/*from w w w.ja va2 s . c o m*/ } layoutIds = map; layoutNames = map2; } return layoutNames.get(id); } }