嗨,我对android(和这里)很新,我正在尝试这样做:
Random random = new Random();
int randomQuestion = random.nextInt(3);
Resources res = getResources();
String[] questions = res.getStringArray(R.array.question_array);
String[] answers = res.getStringArray(R.array.answers[randomQuestion]);
但最后一行显然不起作用。我的xml文件如下所示:
<array name = "answers">
<item>@array/questionOneAnswers</item>
<item>@array/questionTwoAnswers</item>
<item>@array/questionThreeAnswers</item>
</array>
<string-array name = "questionOneAnswers">
<item>Question 1, Answer 1</item>
<item>Question 1, Answer 2</item>
<item>Question 1, Answer 3</item>
<item>Question 1, Answer 4</item>
</string-array>
<string-array name = "questionTwoAnswers">
<item>Question 1, Answer 1</item>
<item>Question 1, Answer 2</item>
<item>Question 1, Answer 3</item>
<item>Question 1, Answer 4</item>
</string-array>
<string-array name = "questionThreeAnswers">
<item>Question 1, Answer 1</item>
<item>Question 1, Answer 2</item>
<item>Question 1, Answer 3</item>
<item>Question 1, Answer 4</item>
</string-array>
我也不能这样做:
String[] [] answers = res.getStringArray(R.array.answers);
如何访问嵌套数组?