I want to make static function with Alert dialog which return boolean value.
In C# it looks like:
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
//do something
}
else if (dialogResult == DialogResult.No)
{
//do something else
}
In Kotlin i have class with companion object
class Dialog {
companion object {
fun question(context: Context, title: String, message: String) {
AlertDialog.Builder(context).apply {
setIcon(R.drawable.ic_question)
setTitle(title)
setMessage(message)
setPositiveButton("YES", DialogInterface.OnClickListener { dialog, which ->
})
setNegativeButton("NO", DialogInterface.OnClickListener { dialog, which ->
})
}.show()
}
}
}
And i want to return Boolean result from question function.
I want to use this function in my activity like this:
if(Dialog.question(this,"Title", "Message")) {
//something
} else {
//something
}
Is it possible?