如何使用导航组件safeargs将列表作为参数传递给片段 [英] How to pass a List as an argument to a Fragment using Navigation Component safeargs

查看:136
本文介绍了如何使用导航组件safeargs将列表作为参数传递给片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档讨论了如何发送简单整数和字符串.例如:

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

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

在原始片段中:

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

在目标片段中:

val receivedInt = DestinationFragmentArgs.fromBundle(arguments).myIntArg

但是要说而不是myIntArg,我想发送一个整数列表(myIntListArg).我该怎么做?我在论点中会使用什么 app:argType ?

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?

推荐答案

在撰写本文时.数组参数已添加.当前使用2.1.0-alpha04

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

应该这样做

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

请注意,"className"必须设置为"com.google.package.ClassName"

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

这篇关于如何使用导航组件safeargs将列表作为参数传递给片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆