Skip to content Skip to sidebar Skip to footer

Show String Keys Instead Of Values

Is it possible to show the keys of my strings in strings.xml instead of the value, would be cool to check which key is it directly in the UI. for example

Solution 1:

use Resources.getResourcesName(int),

Return the full name for a given resource identifier

here you can find the documentation. You can also use reflection:

privateArrayList<String> getKeysName(Context context, String className) {
        Class c;
        ArrayList<String> fieldsName = newArrayList<String>();
        try {
            c = Class.forName(context.getPackageName() + ".R$" + className);
            Field[] fields = c.getDeclaredFields();
            for (Field f : fields) {
                Log.e("LOG_TAG", " " + f.getName());
                fieldsName.add(f.getName());
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return fieldsName;
    }

and call it like getKeysName(context, "string");, to get, for instance all the keys declared inside string.xml.

Post a Comment for "Show String Keys Instead Of Values"