Reputation: 77
I have an activity with three fragments in it, This is how I communicate between the three fragments:
First I display only FragmentA
in ActivityA
. Based on a RadioButtonSelection
, I add the corresponding FragmentB
(two layouts available) and a FragmentC
. If input in FragmentB
is changed String
, then FragmentC's
views change but if the RadioButton
choice in FragmentA
changes then I remove Fragment
B and FragmentC
and add them again corresponding to input from FragmentA
.
Now, I've implemented a communicator interface in FragmentA
and another in FragmentB
. It looks quite messy. How can I implement a single interface to communicate between the three of them and the activity?
Thanks.
Upvotes: 1
Views: 770
Reputation: 29285
In such circumstances in which multiple fragments and activities want to communicate with each other, two options come in mind.
Recommended
Image source: https://stackoverflow.com/a/24083101/1841194
Upvotes: 2