Skip to content

Instantly share code, notes, and snippets.

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