我想按照Reference drawable from string-array in android
中的说明做一些类似的事情private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
我试过这个.java文件:
int[] descriptions = new int[] {
R.string.description_section1,
R.string.description_section2,
};
但它似乎不是正确的语法。
答案 0 :(得分:2)
按照docs:
中的说明尝试此操作int[] descriptions = {
R.string.description_section1,
R.string.description_section2,
};
答案 1 :(得分:2)
在array.xml中定义数组:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="descriptions">
<item>section1</item>
<item>section1</item>
</string-array>
</resources>
然后试试这个:
String[] descriptions = getResources().getStringArray(
R.array.descriptions);