How to pass a List as an argument to a Fragment using Navigation Component safeargs

て烟熏妆下的殇ゞ 提交于 2020-07-20 09:42:51

问题


The documentation discusses how to send simple integers and strings. For example:

<argument
    android:name="myIntArg"
    android:defaultValue="255"
    app:argType="integer" />

In the origin Fragment:

val action = OriginFragmentDirections.myAction(myInt)
findNavController().navigate(action)

In the destination Fragment:

val receivedInt = DestinationFragmentArgs.fromBundle(arguments).myIntArg

But say instead of myIntArg, I wanted to send a list of integers (myIntListArg). How would I do that? What app:argType would I use in my argument?


回答1:


By the time of writing. Array arguments are already added. Currently using 2.1.0-alpha04

That should be done like this

<argument
        android:name="variableName"
        app:argType="className[]"/>

Note that "className" must be set like "com.google.package.ClassName"



来源:https://stackoverflow.com/questions/53545369/how-to-pass-a-list-as-an-argument-to-a-fragment-using-navigation-component-safea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!