Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all string resources from XML resource file?

I have a resource file called suggestions.xml which is translated to a couple of languages. These XML files contain just <string> values.

Now, I'd like to retrieve all the strings in the current locale's suggestions.xml file. How do I do that? I know I can retrieve single strings by their ID's, but I'd like to get all the strings in the XML file instead.

like image 683
manabreak Avatar asked Mar 15 '23 18:03

manabreak


1 Answers

I wonder why would you need to do this. Still, you can use the generated R class to iterate over all kinds of resources.

Field[] fields = R.string.class.getFields();
String[] stringNames = new String[fields.length];
for (int  i = 0; i < fields.length; i++) {           
    stringNames[i] = fields[i].getName();
}
like image 127
Vesko Avatar answered Apr 07 '23 06:04

Vesko