1

Hi I'm pretty new to android (and here) and I am trying to do this:

    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]);

But that last line clearly doesn't work. My xml file looks like this:

 <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>

I also cant do this:

String[] [] answers = res.getStringArray(R.array.answers);

How do I go about accessing a nested array?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
microflakes
  • 313
  • 2
  • 10

0 Answers0