所以我有用于ListView的自定义适配器
我可以这样设置值:
dataModels.add(new DataModel("Apple Pie", "Android 1.0", "1","September 23, 2008"));
dataModels.add(new DataModel("Banana Bread", "Android 1.1", "2","February 9, 2009"));
...
但是我需要从一些不同的R.array的数据中设置数据
<string-array name="Name">
<item>Apple Pie</item>
<item>Banana Bread</item>
</string-array>
<string-array name="Version">
<item>Android 1.0</item>
<item>Android 1.1</item>
</string-array>
...
答案 0 :(得分:1)
您必须从数组构建每个DataModel
ArrayList<DataModel> dataModels = new ArrayList<DataModel>();
for (int i = 0; i < getResources().getStringArray(R.array.Name).length; i++) {
dataModels.add(new DataModel(
getResources().getStringArray(R.array.Name)[i],
getResources().getStringArray(R.array.Version)[i],
getResources().getStringArray(R.array.Id)[i],
getResources().getStringArray(R.array.Date)[i]));
}