android - 将参数传递给嵌套图 startDestination

标签 android navigation android-navigation-graph

我在单独的文件中创建了多个图表。

第一个是图A 它包括图B . startDestination图B fragment B 有一个名为 的参数AnID

现在我想通过 AnID 来自 图A 图B ( fragment B )

尽管编辑器知道该参数,但生成的代码不考虑该参数:

enter image description here

    val directionB = FragmentADirections.actionFragmentAToGraphB(/* HAS NOT ARGUMENT */)
    findNavController().navigate(directionB)

如何将参数传递给嵌套图?

最佳答案

我发现了这个,但这不是官方的解决方案:

val direction = FragmentADirections.actionFragmentAToGraphB()
findNavController().navigate(direction.actionId, FragmentBArgs(anId).toBundle())
更新:
有人介绍another way通过在行动中定义嵌套图参数

关于android - 将参数传递给嵌套图 startDestination,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60016118/

相关文章:

java - 将 ListView 添加到 fragment 会缩小布局

android - requestFocus 不工作

android - 带导航图的抽屉导航不工作

android - Activity 重新创建后重置导航图

java - 如何在recyclerview中使用listview?

java - Windows 版 Android Studio 安装失败

c# - Windows 7 Phone - 延迟屏幕导航

html - 粘性顶部导航但下拉菜单不显示

html - 为什么 html 中的超链接无法重新定位到其他页面?

android - 使用 setGraph() 以编程方式设置图形会导致应用程序无法在进程终止后恢复堆栈(Jetpack 导航)