Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active September 15, 2023 09:04
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/a6eea38afa7e87d76603f8b5bb42cf7d to your computer and use it in GitHub Desktop.
Save codeforfun-jp/a6eea38afa7e87d76603f8b5bb42cf7d to your computer and use it in GitHub Desktop.
Android Quiz App Kotlin 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