从XML资源文件获取所有字符串资源? [英] Get all string resources from XML resource file?

查看:91
本文介绍了从XML资源文件获取所有字符串资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为suggestions.xml的资源文件,该文件已翻译成多种语言.这些XML文件仅包含<string>值.

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

现在,我想检索当前语言环境的suggestions.xml文件中的所有字符串.我怎么做?我知道我可以按ID检索单个字符串,但是我想在XML文件中获取所有 字符串.

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.

推荐答案

我不知道您为什么需要这样做.不过,您仍然可以使用生成的R类来遍历各种资源.

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();
}

这篇关于从XML资源文件获取所有字符串资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆