-
-
Save codeforfun-jp/a6eea38afa7e87d76603f8b5bb42cf7d to your computer and use it in GitHub Desktop.
Android Quiz App Kotlin 5-2
This file contains 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