Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created October 15, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/8c9910abd040f3b009e6b43f29297e53 to your computer and use it in GitHub Desktop.
Save codingwithsara/8c9910abd040f3b009e6b43f29297e53 to your computer and use it in GitHub Desktop.
4-1
// 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