OnCancelListener is not called in DialogFragment

前端 未结 5 1373
盖世英雄少女心
盖世英雄少女心 2020-12-30 00:30

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

5条回答
  •  北海茫月
    2020-12-30 01:21

    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)}.

提交回复
热议问题