I have a simple AlertDialog
that displays a list of some items and upon clicking one of them, the clicked item is passed back to the enclosing Activity
Actually if you want to use DialogFragment
, you can never add OnCancelListener
or OnDismissListener
to it, since the Dialog Fragment owns callbacks to these methods!
You have 3 options here:
1- go with regular dialogs.
2- set your dialog fragment to cancellable(false) and add a cancel button to the dialog.
3- check @Nikhil Pingle answer.
this is from the documentation of the Dialog Fragment
* Note: DialogFragment own the {@link Dialog#setOnCancelListener
* Dialog.setOnCancelListener} and {@link Dialog#setOnDismissListener
* Dialog.setOnDismissListener} callbacks. You must not set them yourself.
* To find out about these events, override {@link #onCancel(DialogInterface)}
* and {@link #onDismiss(DialogInterface)}.