如何将 ArrayList 元素(项目)放入 TextView?

How to put ArrayList elements (items) into a TextView?

我的 strings.xml 中有一个 ArrayList。我想从中选择元素并将其放入 .setText() 中。我该怎么做?

是否应该在arrays.xml中声明ArrayList?如果是,则使用Context.getResource().getStringArray()选择元素

示例:XML 文件保存在 res/values/strings。xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="planets_array">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
    </string-array>
</resources>

此应用程序代码检索字符串数组:

String[] planets = getResources().getStringArray(R.array.planets_array); 

正在为 textView 赋值:

    TextView textView = (TextView) findViewById(R.id.textView1); 
    textView.setText(planets[1]);  //Venus

阅读更多内容:

http://developer.android.com/guide/topics/resources/string-resource.html