【问题标题】:How to use by navArgs in navigation如何在导航中使用 navArgs
【发布时间】:2020-06-11 05:48:56
【问题描述】:

我想使用by navArgs() 得到ProtocolFragmentArgs。但是工作室提示我navArgs需要通用,我对此一无所知。

【问题讨论】:

  • 您好,您能否使用内联代码来提高代码清晰度? link

标签: android kotlin navigation arguments


【解决方案1】:

您现在可以尝试将数据作为捆绑包发送并检查它是否正常工作。我目前面临同样的问题。让我们都弄清楚。我现在这样做了:

在 startFragment 中

var bundle = Bundle()
    bundle.putParcelable("object",song)
    v.findNavController().navigate(R.id.action_songListFragment_to_playerFragment,bundle)

在接收片段中

val mSong = arguments?.getParcelable<Song>("object")
    v.findViewById<TextView>(R.id.tv_title).text = mSong?.title
    Toast.makeText(context, "${mSong?.title}", Toast.LENGTH_SHORT).show()

等我弄明白了就贴在这里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多