Skip to content

Instantly share code, notes, and snippets.

@abircse
Created February 15, 2021 13:38
Show Gist options
  • Save abircse/52e94ad5a0ff7e600121315ea84c6fb0 to your computer and use it in GitHub Desktop.
Save abircse/52e94ad5a0ff7e600121315ea84c6fb0 to your computer and use it in GitHub Desktop.
AlertDialogExtension
inline fun showMessegeDialogWithAction(ctx: Context, msg: String, btnTxtPositive: String, btnTxtNegative: String, crossinline onPositiveButtonClick: () -> Unit){
val builder = AlertDialog.Builder(ctx)
builder.setMessage(msg)
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.setPositiveButton(btnTxtPositive) { dialogInterface, which ->
onPositiveButtonClick.invoke()
}
builder.setNegativeButton(btnTxtNegative) { dialogInterface, which ->
dialogInterface.dismiss()
}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(false)
alertDialog.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment