简体   繁体   English

如何使用导航组件安全参数将列表作为参数传递给片段

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

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 ).但是说而不是myIntArg ,我想发送一个整数列表( myIntListArg )。 How would I do that?我该怎么做? What app:argType would I use in my argument?我会在我的论点中使用什么app:argType

You can add array arguments like this:您可以像这样添加数组参数:

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

Note that "className" must be set like "com.google.package.ClassName".请注意,“className”必须设置为“com.google.package.ClassName”。

This is how you can pass list of integers.这就是您可以传递整数列表的方式。

    <argument
        android:name="yourVariableName"
        app:argType="integer[]"
        app:nullable="false"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用导航组件安全参数将枚举作为参数传递给片段的正确方法是什么 - What is the correct way to pass an Enum as an argument to a Fragment using Navigation Component safeargs 导航组件:将安全参数从活动传递到片段 - Navigation Component: pass safeArgs from activity to a fragment 如何使用导航类型 safeargs 插件将 Parcelable 类型的对象传递给 Fragment - How to pass object of type Parcelable to a Fragment using Navigation type safeargs plugin 使用 SafeArgs 将参数从片段传递到活动 - Passing argument from fragment to activity using SafeArgs 如何将 function 作为参数传递给目标片段 - Android 导航组件 - How to pass a function as an argument to a destination fragment - Android Navigation Component Android 导航组件通过 safeArgs 和深度链接传递参数 - Android navigation component passing argument with safeArgs and deep link 当参数具有默认值时,为什么我不能使用导航组件将参数传递给片段? - Why can't I pass an argument to fragment using navigation component when that argument has a default value? 如何在使用导航组件和 safeArgs 从回收器视图导航到片段时添加共享元素转换? - How to add shared element transition when navigating from recycler view to a fragment while using navigation components and safeArgs? 使用 SafeArgs 和 Mockito 测试导航组件 - Test Navigation Component with SafeArgs and Mockito 将 SafeArgs 与 Proguard 和导航架构组件一起使用时出现 ClassNotFoundException? - ClassNotFoundException when using SafeArgs with Proguard and Navigation Architecture Component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM