-
-
Save codeforfun-jp/d4afae85cc089aa03ce9aec302ac1bdf to your computer and use it in GitHub Desktop.
[Kotlin Quiz ver2] 5-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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