Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active September 19, 2023 06:41
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 codeforfun-jp/beb7f5da025e5a646f1d69a22d08cadb to your computer and use it in GitHub Desktop.
Save codeforfun-jp/beb7f5da025e5a646f1d69a22d08cadb to your computer and use it in GitHub Desktop.
Java Quiz - 2023 - 5
public void showNextQuiz() {
/* 省略 */
}
@Override
public void onClick(View view) {
// どの解答ボタンが押されたか
Button answerBtn = findViewById(view.getId());
String btnText = answerBtn.getText().toString();
String alertTitle;
if (btnText.equals(rightAnswer)) {
alertTitle = "正解!";
rightAnswerCount++;
} else {
alertTitle = "不正解...";
}
// ダイアログを作成
new MaterialAlertDialogBuilder(this)
.setTitle(alertTitle)
.setMessage("答え : " + rightAnswer)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (quizCount == QUIZ_COUNT) {
// 結果画面へ移動
} else {
quizCount++;
showNextQuiz();
}
}
})
.setCancelable(false)
.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment