1

I would like to make the questions and answer appear randomly in a quiz activity.

Here is a snippet from QuizActivity.java

private void updateQuestion(){
    mQuestionView.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
    mButtonChoice1.setText(mQuestionLibrary.getChoice1(mQuestionNumber));
    mButtonChoice2.setText(mQuestionLibrary.getChoice2(mQuestionNumber));
    mButtonChoice3.setText(mQuestionLibrary.getChoice3(mQuestionNumber));
    mButtonChoice4.setText(mQuestionLibrary.getChoice4(mQuestionNumber));

    mAnswer = mQuestionLibrary.getCorrectAnswer(mQuestionNumber);
    mQuestionNumber++;
}

private void updateScore(int point) {
    mScoreView.setText("" + mScore);
}

Here is a snippet of my code in QuestionLibrary.java

public String getQuestion(int a) {
        String question = mQuestions[a];
        return question;
    }
    public String getChoice1(int a) {
        String choice0 = mChoices[a][0];
        return choice0;
    }
    public String getChoice2(int a) {
        String choice1 = mChoices[a][1];
        return choice1;
    }
    public String getChoice3(int a) {
        String choice2 = mChoices[a][2];
        return choice2;
    }
    public String getChoice4(int a) {
        String choice3 = mChoices[a][3];
        return choice3;
    }
    public String getCorrectAnswer(int a) {
        String answer = mCorrectAnswers[a];
        return answer;
    }
Chris
  • 4,450
  • 3
  • 38
  • 49
jake Ben
  • 11
  • 1
  • I'd highly recommend having a look at `Collections#shuffle` - but you'll have to use some kind of `List` instead – MadProgrammer Apr 04 '17 at 04:14
  • Possible duplicate of [Random shuffling of an array](http://stackoverflow.com/questions/1519736/random-shuffling-of-an-array) – Joe C Apr 04 '17 at 05:37

0 Answers0