this question might be very noobish but I’m just not able to find a right solution.
So here is my problem:
I want do display the data (a java.util.List with my TaskObjects) in multiple ExpandableLists (lets say 5) each in a own Fragment so that the user is able to swipe between the different Lists.
At the moment I have a MainFragmentActivity that contains the java.util.List, the PageViewer and a ‘extended’ FragmentPagerAdapter (like TabsAdapter) that contains the Tabs AllTaskFragment and OverDueTaskFragment. These two Fragments have each a own ExpandableList and ExpandableListAdapter (writen by me).
Now when the user clicks on a child in any ExpandableLists how do i need to notify the other Fragments ExpandableListAdapter to update? I tried to call the MainFragmentActivity and from there call all Fragments but then the fragments ExpandableListAdapters were ‘null’, but why?
update:
I guess I solved the issue, atm Is working with:
If something changes in any ExpandableListAdapter, I call updateTabs() in
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 the method
public void updateFragment() {
adapter.notifyDataSetChanged();
}
Is this a good approach? Or will this maybe rise some issues?
The key thing for such applications is to keep track of the ArrayAdapters. If you call
ArrayAdapter.notifyDataSetChanged(), it will tell its view to update.