this question can be very noob, but I just can’t find the right solution.
So here is my problem:
I want to show the data (a java.util.List with my TaskObjects ) in several ExpandableLists (let’s say 5) each in its own fragment so that the user can scroll between different lists. At the moment, I have MainFragmentActivity , which contains java.util.List , PageViewer and an 'extended' FragmentPagerAdapter (like TabsAdapter ) that contains the AllTaskFragment and OverDueTaskFragment . These two Snippets have each ExpandableList and ExpandableListAdapter (written by me).
Now that the user clicks on the child in any ExpandableLists , how do I need to notify other ExpandableListAdapter fragments to update? I tried calling MainFragmentActivity and calling all the fragments from there, but then the ExpandableListAdapters fragments were "null", but why?
update:
I think I solved the problem, atm works with:
If something changes in any ExpandableListAdapter, I call updateTabs () on
MainFragmentActivity
public void updateTabs() { for(int i = 0 ; i < tabsAdapter.getCount() ; i++) { UpdateableFragment updateableFragment = (UpdateableFragment) getSupportFragmentManager().findFragmentByTag(makeFragmentName(mViewPager.getId(),i)); updateableFragment.updateFragment(); } } private String makeFragmentName(int viewId, int index){ return "android:switcher:" + viewId + ":" + index; }
which simply calls in each fragment a method
public void updateFragment() { adapter.notifyDataSetChanged(); }
Is this a good approach? Or can it cause some problems?
source share