How can I parse the strings.xml file in Android into an ArrayList? [duplicate]

时间:2022-11-26 02:07:14

This question already has an answer here:

这个问题在这里已有答案:

I would like to get all values that are stored in the strings.xml file and store them in an array list that holds just strings. What would be the easiest way to achieve this??

我想获取存储在strings.xml文件中的所有值,并将它们存储在只包含字符串的数组列表中。实现这一目标最简单的方法是什么?

1 个解决方案

#1


0  

You can do that with this one-liner:

你可以用这个单线程做到这一点:

ArrayList<String> list = new ArrayList(Arrays.asList(getResources().getStringArray(R.array.strings)));//where R.array.strings is a reference to your resource

#1


0  

You can do that with this one-liner:

你可以用这个单线程做到这一点:

ArrayList<String> list = new ArrayList(Arrays.asList(getResources().getStringArray(R.array.strings)));//where R.array.strings is a reference to your resource