My Activity contains a ViewPager and it's custom Adapter which extends FragmentStatePagerAdapter. ViewPager contains 3 fragments
Code to remove Fragments from the ViewPager
MainActivity
public void deleteElement(){
final int currentItem = mViewPager.getCurrentItem();
mPagerAdapter.removeItem(currentItem);
mPagerAdapter.notifyDataSetChanged();
}
CustomPagerAdapter
private ArrayList<Item> data;
public void removeItem(int index){
data.remove(index);
}
when removing the middle Fragment (index 1):
- from
datai'm removing the correctitem. - Problem is that i (i guess)
Fragment3 is removed afternotifyDataSetChangedand the currentFragmentis still the fragment that the user saw and the data that is being loaded is from theSavedInstancebundle
So the end result that the user still see the same Fragment that he tried to remove which is kinda suck for him.
Ideas?
***** EDIT ******
seems like ViewPager2 Features might solve this issue and many other issues as well