DialogFragment.getDialog returns null

前端 未结 5 1379
感动是毒
感动是毒 2020-12-02 16:30

I am trying to get the Dialog I have created with an extended DialogFragment using DialogFragment.getDialog() but it returns null.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 17:20

    public class Dialog extends DialogFragment {
    
    private DialogListener dialogListener;
    
    
    public void setDialogListener(DialogListener dialogListener) {
        this.dialogListener = dialogListener;
    }
    
    
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.layout_dialog, null);
        return view;
    }
    
    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (null != dialogListener) {
            dialogListener.onDismiss();
        }
    }
    
    public interface DialogListener {
        void onDismiss();
    }
    

    }

    in Activity ...

      Dialog  dialog= new Dialog();
            dialog.setDialogListener(new Dialog.DialogListener() {
                @Override
                public void onDismiss() {
                    Foo()..
                }
            });
    

提交回复
热议问题