-
-
Save codingwithsara/8c9910abd040f3b009e6b43f29297e53 to your computer and use it in GitHub Desktop.
4-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tmpArrayをquizArrayに追加する | |
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