本文介绍了清除dialogfragment时刷新片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以检测到何时关闭DialogFragment以便更新其父片段?

Is there any way I can detect when a DialogFragment is dismissed, so that i can update its parent fragment?

推荐答案

您可以添加侦听器并覆盖片段对话框的onDismiss:

You can add a listener and override the onDismiss of your fragment dialog :

public class DismissDialog extends DialogFragment {
    private DialogInterface.OnDismissListener onDismissListener;

    public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
        this.onDismissListener = onDismissListener;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (onDismissListener != null) {
            onDismissListener.onDismiss(dialog);
        }
   }
}

然后,在父级上,设置一个侦听器:

Then, on the parent, you set a listener :

DismissDialog d = new DismissDialog();
d.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {

        }
    });
d.show(getSupportFragmentManager(), "sometag");

这篇关于清除dialogfragment时刷新片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 04:54