【问题标题】:Custom DialogFragment onDismiss not called/working自定义 DialogFragment onDismiss 未调用/工作
【发布时间】:2016-05-19 17:31:08
【问题描述】:

问题是,如果我使用 FragmentsTransaction,onDismiss 不会被触发:

FragmentTransaction transaction = getFragmentManager().beginTransaction();

// For a little polish, specify a transition animation
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

// To make it fullscreen, use the 'content' root view as the container
// for the fragment, which is always the root view for the activity
transaction.add(android.R.id.content, _dialogInfo).addToBackStack(null).commit();

但如果我使用 show(),则会调用 onDismiss 事件:

_dialogInfo.show(getFragmentManager(), DialogFragmentInfo.TAG);

onDismiss 在自定义 DialogFragment 中实现,如下所示:

@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);
}

我不确定为什么会这样,并且我在文档中没有找到任何解释。

【问题讨论】:

    标签: java android dialogfragment


    【解决方案1】:

    来自DialogFragment,文档,生命周期部分:

    这意味着您应该使用 show(FragmentManager, String) 或 show(FragmentTransaction, String) 添加 DialogFragment 的实例 到您的 UI,因为这些跟踪 DialogFragment 应如何删除 当对话框被关闭时它自己。

    据推测,show() 做了一些额外的工作以按预期方式关闭对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多