【问题标题】:Pass argment to a nested graph's startDestination将参数传递给嵌套图 startDestination
【发布时间】:2020-02-01 10:42:10
【问题描述】:

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

第一个是GraphA,它包括GraphBGraphBstartDestinationFragmentB,它有一个名为 AnID

的参数

现在我想将 AnIDGraphA 传递给 GraphB (FragmentB)

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

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

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

【问题讨论】:

    标签: android navigation android-navigation-graph


    【解决方案1】:

    我找到了这个,但这不是官方解决方案:

    val direction = FragmentADirections.actionFragmentAToGraphB()
    findNavController().navigate(direction.actionId, FragmentBArgs(anId).toBundle())
    
    更新:

    有人通过在操作中定义嵌套图参数来介绍another way

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 2018-10-24
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多