小编cew*_*phi的帖子

如何使用导航组件导航嵌套的 DialogFragment 而不破坏第二个?

情况:

  1. 片段 A 导航到 DialogFragment B(单击按钮时)
  2. 在 B 的 PositiveButton 给定条件下 -> 导航到 DialogFragment C

问题:

当单击 DialogFragment B 的确认按钮时,B 会收到此 DialogFragment 的 onDestroy 调用。无论如何,这是有意的,当 B 不需要导航到 C 时没有问题。

但是:当 B 按请求导航到 C 时,会发生以下情况:

  • C 弹出几分之一秒,然后消失
  • 并且导航控制器的当前位置不是A。我需要一次后按才能再次到达 A

我也不希望导航控制器位于 A 处。我希望它位于 C 处显示 DialogFragment。

执行:

片段实现

class FragmentA : Fragment() {
...
    // is assigned as onClick listener to the button
    fun onClickButton() {
        if (findNavController().currentDestination?.id == R.id.FragmentANavId) {
            val action = FragmentADirections.actionFragmentAToDialogFragmentB()
            findNavController().navigate(action)
    }
}

// …
Run Code Online (Sandbox Code Playgroud)

android nested android-dialogfragment android-architecture-navigation

5
推荐指数
1
解决办法
2547
查看次数