如何将一个片段与另一个片段连接

How to Connect with one fragment with another fragment

I am new with Fragment. My problem is how to do it, when I selected my (OneFragment.java) radio button is Selected then another (Threefragment.java) will also be selected and show the data.

Here some Images Of My Product, I hope anyone can help me out.

This is My FirstFragment.Java

This is My ThirdFragment.Java

片段之间有多种通信方式。最好的方法是使用片段管理器。

在片段 3 中,初始化侦听器。

setFragmentResultListener("requestKey") { key, bundle ->
    // Any type can be passed via to the bundle
    val result = bundle.getString("data")
    // Do something with the result...
}

从片段 1 开始,您可以借助请求密钥和捆绑包传递数据。

setFragmentResult("requestKey", Bundle())

确保片段版本是最新的。

您可以使用共享 ViewModel 在片段之间传递数据,使用可观察对象保留值并通过共享 ViewModel 在任何片段中显示。 这是共享 ViewModel

的正确 Implementation