Issue
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
Solution
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.
Answered By - Blackbelt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.