简体   繁体   中英

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

There are many ways to communicate between fragments. The best way is to use fragment managers.

In fragment 3, initialize the listener.

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

From fragment 1, you can pass the data with the help of request keys and bundle.

setFragmentResult("requestKey", Bundle())

Make sure the fragment version is up to date.

You can use shared ViewModel to passing the data between fragments using observables to retain the values and shows in any fragment through shared ViewModel. Here is proper Implementation of shared ViewModel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM