3

When using positiveButton and negativeButton in Anko's alert builder, it seems both of them result in closing the dialog, even if dismiss() is not called. Is there any way to keep the dialog open after clicking a button (if there are types other than positiveButton/negativeButton, that's fine too)?

alert {
    title = "Add Board"
    customView {
        ....
    }
    positiveButton("OK") { doSomeFunction() }
    negativeButton("Close"){}
}.show()
Parker
  • 8,539
  • 10
  • 69
  • 98

2 Answers2

7

For anyone that may have this issue in the future, this is how you can accomplish this in Kotlin

val myAlert = alert {
    title = "Add Board"
    customView {
        ....
    }
    positiveButton("OK") { /*Keep blank, we'll override it later*/}
    negativeButton("Close"){}
    }.show()

//You can use BUTTON_NEGATIVE and BUTTON_NEUTRAL for other buttons
(myAlert as AlertDialog).getButton(AlertDialog.BUTTON_POSITIVE)
    .setOnclickListener{
        doSomeFunction()
    }
Parker
  • 8,539
  • 10
  • 69
  • 98
-1
alert {
  title = "Add Board"
  customView {
    ....
  }
  positiveButton("OK") { /*Keep blank, we'll override it later*/}
  negativeButton("Close"){}

  isCancelable = false // Disable close here
}.show()