3

I'm using an AlertDialog with 2 buttons (one positive, one negative). I've set a handler for those buttons which doesn't mention dismiss. Indeed after clicking, I don't want the dialog to close. However, it seems that as soon as we click on a positive/negative button on an AlertDialog, it always get closed.

Is there a way to prevent the dialog from closing after clicking on any button ?

Thanks,

Vincent

Vincent
  • 1,013
  • 14
  • 33
  • See similar question with different answers: http://stackoverflow.com/questions/2620444/android-how-to-prevent-dialog-closed-or-remain-dialog-when-button-is-clicked – AlikElzin-kilaka Jun 14 '12 at 16:49

3 Answers3

5

Use custom layout for Dialog and you will be happy!

Rubycon
  • 18,156
  • 10
  • 49
  • 70
1

Use a custom dialog, not an AlertDialog.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
0

You can also create a new Activity and assign it the theme dialog in your manifest with

<activity android:name="MyDialogActivity" android:theme="@android:style/Theme.Dialog" />
Kevin Gaudin
  • 9,927
  • 3
  • 32
  • 34
  • It depends on the content of the dialog. A dialog should be a simple question with a quick answer. If there is a need for a button which does not dismiss the Dialog then this lets me think that there might be some added complexity in this Dialog which could actually deserve an Activity... But with the info given in the question, this is pure speculation ;-) I just wanted to give this alternative which is not well-known. – Kevin Gaudin Feb 02 '11 at 02:09