从父片段传递到子片段的值为空

问题描述 投票:0回答:0

我想将值“Branch 1”从我的父片段传递到它的子片段。但是,当我尝试使用

getString()
检索子片段中的值时,该值为空。

父片段中传值代码:

val bundle = Bundle()
bundle.putString("store", "Branch 1")

val childFragment = PryceGasFragment()
childFragment.arguments = bundle

子片段中检索值的代码:

val store = arguments?.getString("store")

Toast.makeText(requireContext(), "The store you picked is $store", Toast.LENGTH_SHORT).show()

我这里用了

makeText()
来判断是否传值。然而,它是空的。

免责声明:我只是在网上搜索如何传递这些值,我只是复制了代码。

我尝试了将值从父片段传递到子片段的不同方法。然而,它们似乎都不起作用:\

android kotlin android-fragments parent-child
© www.soinside.com 2019 - 2024. All rights reserved.