本文介绍了获取Android中strings.xml文件中存在的字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在strings.xml文件中显示字符串列表.

I want the list of strings present in the strings.xml file.

有人知道如何获得吗???我发现的一件事是,它在R.java中按顺序分配了ID,但是如何获取起始ID尚不清楚.

Does anyone knows how to get it??? One thing I found is it assigns the ids in sequential order inside R.java but how to get the starting id is not clear.

例如,我的s​​trings.xml中有100个字符串,如下所示,我想一次读入,而不是像个人一样给getResources().getString(int id)

For Example I have 100 Strings in my strings.xml like below and I want to read in at a time not like giving getResources().getString(int id) for individual.

<string name="app_label">Calendar</string>
<string name="what_label">What</string>
<string name="where_label">Where</string>
<string name="when_label">When</string>
<string name="timezone_label">Time zone</string>
<string name="attendees_label">Guests</string>
<string name="today">Today</string>
<string name="tomorrow">Tomorrow</string>

推荐答案

如果要访问 strings.xml 文件中的所有字符串,可以在 R.string上使用反射类.可以在,您只需要用字符串替换可绘制对象即可.

If you want to access all the Strings from the strings.xml file you could use reflection on the R.string class. An example can be found in this answer, you'll just need to replace drawables with strings.

这篇关于获取Android中strings.xml文件中存在的字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:10