Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created October 24, 2024 05:53
Show Gist options
  • Save codeforfun-jp/d4afae85cc089aa03ce9aec302ac1bdf to your computer and use it in GitHub Desktop.
Save codeforfun-jp/d4afae85cc089aa03ce9aec302ac1bdf to your computer and use it in GitHub Desktop.
[Kotlin Quiz ver2] 5-2
private fun checkAnswer(view: View) {
// どの解答ボタンが押されたか
val answerBtn: Button = findViewById(view.id)
val btnText = answerBtn.text.toString()
// ダイアログのタイトルを作成
val alertTitle: String
if (btnText == rightAnswer) {
alertTitle = "正解!"
rightAnswerCount++
} else {
alertTitle = "不正解..."
}
// ダイアログを作成
MaterialAlertDialogBuilder(this)
.setTitle(alertTitle)
.setMessage("答え : $rightAnswer")
.setPositiveButton("OK") { dialogInterface, i ->
checkQuizCount()
}
.setCancelable(false)
.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment