Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created November 5, 2024 05:55
Show Gist options
  • Save codeforfun-jp/a6bf8dfc0bc27bb54481b90dfc7d36bd to your computer and use it in GitHub Desktop.
Save codeforfun-jp/a6bf8dfc0bc27bb54481b90dfc7d36bd to your computer and use it in GitHub Desktop.
[Java Quiz ver2] 4-4
private void showNextQuiz() {
// クイズカウントラベルを更新
binding.countLabel.setText(getString(R.string.count_label, quizCount));
// quizArrayからクイズを1つ取り出す
ArrayList<String> quiz = quizArray.get(0);
// 問題文(都道府県名)を表示
binding.questionLabel.setText(quiz.get(0));
// 正解をrightAnswerにセット
rightAnswer = quiz.get(1);
// クイズ配列から問題文(都道府県名)を削除
quiz.remove(0);
// 正解と選択肢3つをシャッフル
Collections.shuffle(quiz);
// 解答ボタンに正解と選択肢3つを表示
binding.answerBtn1.setText(quiz.get(0));
binding.answerBtn2.setText(quiz.get(1));
binding.answerBtn3.setText(quiz.get(2));
binding.answerBtn4.setText(quiz.get(3));
// このクイズをquizArrayから削除
quizArray.remove(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment