0

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

<string name="jobs_key">Jobs</string>

i would like to show in the UI jobs_key instead of Jobs

AdrianoCelentano
  • 2,461
  • 3
  • 31
  • 42

1 Answers1

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:

  private ArrayList<String> getKeysName(Context context, String className) {
        Class c;
        ArrayList<String> fieldsName = new  ArrayList<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.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305