# Alertdialog - Don't close the window after clicking the OK button

**URL:** <https://discuss.kotlinlang.org/t/alertdialog-dont-close-the-window-after-clicking-the-ok-button/27576>\
**Category:** Uncategorized\
**Created:** [November 3, 2023, 2:38pm UTC](https://discuss.kotlinlang.org/t/alertdialog-dont-close-the-window-after-clicking-the-ok-button/27576 "2023-11-03T14:38:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![d9C](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/d9c/32/10548_2.png) [@d9C](https://discuss.kotlinlang.org/u/d9C)\
**Post date:** [November 3, 2023, 2:38pm UTC](https://discuss.kotlinlang.org/t/alertdialog-dont-close-the-window-after-clicking-the-ok-button/27576/1 "2023-11-03T14:38:11Z")

</div>

Hey,

The alertdialog should not close after clicking the OK button. At best, the OK button should be deactivated and gray and only after input should the button be activated and colored.

```auto
  var builder = AlertDialog.Builder(this)
            builder.setTitle("Hinzufügen")
            builder.setMessage("Füge etwas deiner Liste hinzu!")

            var input = EditText(this)
            input.hint="Hinzufügen"
            input.inputType = InputType.TYPE_CLASS_TEXT
            builder.setView(input)
            input.addTextChangedListener {}

            builder.setPositiveButton("OK") { _, _ -> //logik die Passiert bei Button drücken(ok-button vom alert)
                if (input.text.isNotEmpty()){
                    shoppingItems.add(input.text.toString())
                    Toast.makeText(applicationContext, "Hinzugefügt", Toast.LENGTH_SHORT).show()
                }else{
                    Toast.makeText(applicationContext, "Nichts eingetragen!", Toast.LENGTH_SHORT).show()
                }
                itemAdapter.notifyDataSetChanged()
            }

            builder.setNegativeButton("Abbrechen"){_, _ ->
                Toast.makeText(applicationContext,"Abgebrochen", Toast.LENGTH_SHORT).show()

            }

            itemAdapter.notifyDataSetChanged()
            builder.show()

```

thx for help
