From the very first day of native Android coding, using AlertDialog in Java is struggled a bit because the programer had to write a bunch of code lines to create such a simple dialog.
Later, that Android guy made friend with Kotlin. And up to now, Kotlin is here to save your day with his ultimate ability calls “Extension Function”. This essay aims to guide how to create and easily use Choice Dialog extensions in Kotlin.
Let’s get started
First, you have to create a custom xml file for a choice dialog. Use this code below for example:
Finally, just create a new Kotlin extension file and paste this.
How to use
Simply call function choiceAlert in your fragment or activity.
choiceAlert("Your title here","Your message here") {
positiveButton("Postive button title here") {
//TODO
}
negativeButton("Negative button here") {
//TODO
}
}.show()