1

How to prevent AlertDialog box from closing down when a button is pressed. E.g. Currently when I press "Got it" button the dialog box closes but I don't want it to close, I want it to keep showing up. Basically, I have a button there but I don't want it to close the AlertDialog when pressed.

AlertDialog.Builder builder = new AlertDialog.Builder(this)
        .setTitle("Message")
        .setMessage("First message")
        .setCancelable(true)
        .setNegativeButton("Got it", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                }});
        AlertDialog alert = builder.create();
        alert.show();
Henry
  • 1,042
  • 2
  • 17
  • 47
  • I had the same problem, I think AlertDialog.Builder have this behaviour, I ended up with doing a Dialog that is created later by builder.create(); – Opiatefuchs Feb 24 '15 at 14:35
  • 1
    possible duplicate of [How to prevent a dialog from closing when a button is clicked](http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked) – Psypher Feb 24 '15 at 14:35
  • You can find the answer in this [link](http://stackoverflow.com/a/7636468/1830137). – Mel Feb 24 '15 at 14:47
  • I already had a look at the links you guys provided but there don't work. – Henry Feb 24 '15 at 14:50
  • Try this : http://stackoverflow.com/questions/4016313/how-to-keep-an-alertdialog-open-after-button-onclick-is-fired – Josef Feb 24 '15 at 15:36

0 Answers0