In my main Activity, I have a DialogFragment that contains a FragmentTabHost. I have two tabs, one that is a DialogFragment and one that is a ListFragment. When either the 'OK' button is pressed in the inner DialogFragment or when an element in the ListFragment is pressed, I want to pass two Strings (that are entered in two TextView's in the inner DialogFragment and are displayed in each element in the ListFragment) back to the Activity, but I am unsure of how to do this with multiple levels of Fragments.
Any help is appreciated!
There's no magic.
You can achieve with two approaches.
Create interface and class to pass the data through child Fragment to Activity. You don't need to modify bridged
TabHostFragment
as Fragment always rely on its mother Context (Activity) no matter how many fragments wrap the fragment.First, declare interface.
And, implement interface in Activity.
Finally, let child Fragment acknowlege that mother Activity has the callback listener.
I prefer to use Otto in order to publish and subscribe data.
To subscribe event for listening in Activity,
And, publish event in anywhere in Fragment.