I have an app with two fragments and I want to implement the ViewPager and ActionBarTabs to it. My question is: Is there any way to recreate my ListFragment each time when user moves camera in my MapFragment ? Each move assigns different values to an array which I use to populate the ListFragment. I have looked at this link Synchronize all the ListView in a ViewPager but it looks too complicated. Please help. Take in consideration that I can't use notifyDataSetChanged() on adapter because I want to keep my MapFragment as it is and not recreate it.
You could try making an Interface with an update method like so
public interface UpdatingFragment {
public void update();}
Then have your ListFragment implement this interface. And in the update method recreate the list in your ListFragment.
public class MyListFragment extends ListFragment implements UpdatingFragment{
@override
public void update(){
//whatever code you use to update your fragment
}
Then call this method from your PagerAdapter
@Override
public int getItemPosition(Object item) {
if (item instanceof UpdatingFragment) {
((UpdatingFragment) item).update();
}
//don't recreate fragment
return super.getItemPosition(item);
}
Now if you call notifyDataSetChanged() on your viewpager adapter, it should hopefully update your ListFragment without affecting the map. Call this every time the user moves the camera in the map fragment.