Skip to content

Instantly share code, notes, and snippets.

@bdivljak91
Created August 30, 2019 08:24
Show Gist options
  • Save bdivljak91/cab646e1d6d22453ac646d3fdab70f82 to your computer and use it in GitHub Desktop.
Save bdivljak91/cab646e1d6d22453ac646d3fdab70f82 to your computer and use it in GitHub Desktop.
Show dilaog- Activity extension function
fun Activity.showDialog(title: String,
message: String,
positiveButtonFunction: () -> Unit = {},
negativeButtonFunction: () -> Unit = {},
positiveButtonText: String = "YES",
negativeButtonText: String = "NO") {
val builder = AlertDialog.Builder(this)
builder.setTitle(title)
builder.setMessage(message)
// Set a positive button and its click listener on alert dialog
builder.setPositiveButton(positiveButtonText) { _, _ ->
positiveButtonFunction
}
builder.setNegativeButton(negativeButtonText) { _, _ ->
negativeButtonFunction
}
val dialog: AlertDialog = builder.create()
dialog.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment