Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active Nov 22, 2020
Embed
What would you like to do?
QuizApp 4.1
quizArray.add(tmpArray);
}
}
public void showNextQuiz() {
// クイズカウントラベルを更新
countLabel.setText("Q" + quizCount);
// ランダムな数字を取得
Random random = new Random();
int randomNum = random.nextInt(quizArray.size());
// randomNumを使って、quizArrayからクイズを一つ取り出す
ArrayList<String> quiz = quizArray.get(randomNum);
// 問題文(都道府県名)を表示
questionLabel.setText(quiz.get(0));
// 正解をrightAnswerにセット
rightAnswer = quiz.get(1);
// クイズ配列から問題文(都道府県名)を削除
quiz.remove(0);
// 正解と選択肢3つをシャッフル
Collections.shuffle(quiz);
// 解答ボタンに正解と選択肢3つを表示
answerBtn1.setText(quiz.get(0));
answerBtn2.setText(quiz.get(1));
answerBtn3.setText(quiz.get(2));
answerBtn4.setText(quiz.get(3));
// このクイズをquizArrayから削除
quizArray.remove(randomNum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment