updating data in ListViews displayed with a FragmentPagerAdapter

31 views Asked by At

i try to display Datasets in severel Listview in a fragment in a FragmentPagerAdapter.

The different datasets partly depend on each other (if displayed data in tab A get's changed, data in tab B should be changed as a result.). If data is changed in 1 Listview I give the changed data to the ParentFragment via an interface I implemented in the adapter of the listview. after that I want to give every fragment in every tab the new datasets, but I don't really know how to contact the other tabs from outside the fragment.

I found a suboptimal way by overriding the notifyDataSetInvalidated() in the adapter by calling the interface for new data from the parentfragment and then call notifyDataSetChanged(), but it just works with the tabs out of side ( "tab i made the changes in" +/- 1 are preloaded so they display the old data).

could please someone tell me a better way to handle it? i have read several threads on this topic, but it either didn't work for me or I just didn't understand it (possible affiliate to language)

1

There are 1 answers

0
Hoàn Lê On

Another way is to use EventBus. Every fragment that you want to update the data will listen to the event.

When the first list changes, post an event, other fragments will receive the notification and update themselves.

You can find the EventBus here