Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active November 22, 2020 01:42
Show Gist options
  • Save codeforfun-jp/6d9d2d83d1fdfb75e4a15e1a220190d4 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/6d9d2d83d1fdfb75e4a15e1a220190d4 to your computer and use it in GitHub Desktop.
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