gpt4 book ai didi

java - 自定义 DialogFragment onDismiss 未调用/工作

转载 作者:行者123 更新时间:2023-11-30 10:44:44 27 4
gpt4 key购买 nike

问题是如果我使用 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);
}

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

最佳答案

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

This means you should use show(FragmentManager, String) or show(FragmentTransaction, String) to add an instance of DialogFragment to your UI, as these keep track of how DialogFragment should remove itself when the dialog is dismissed.

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

关于java - 自定义 DialogFragment onDismiss 未调用/工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37330268/

27 4 0