1
votes

Hy, I am quite new to android development and I am trying for a while to establish a communication between my custom dialog fragment that extends DialogFragment and contains four buttons and the fragments from view pager.

My view pager adapter extends FragmentStatePagerAdapter and contains 7 tabs, but for each tab I create the same fragment that has a recyclerView but diferent data for list. The idea is that vhen I click on a button in dialog fragment, it will order my recyclerViews depending on what button was pressed.

I was thinking to use an inerface in dialog that sends the data to activity and from here to update fragment recyclerview. The only problem in my solution is that in activity I have to call the fragment by tag and because of the fact that my fragment is in the view pager, it is not added to backstck. Can anybody help me to set the tag or does anybody know how to do this? Please Help!!

1

1 Answers

0
votes

In all my applications dialogs communicate with other parts of application through event bus (I use GreenRobot's EventBus). The dialog just posts SomeDialog.SomeButtonClickedEvent to event bus, whereas the Fragment which is interested in these events registers itself to event bus in onStart() (unregisters in onStop()).

Usage of event bus for such a communication is much less coupling than interface based approach (components do not need to know about each other).