几天来,我一直在努力在我的应用程序中构建允许用户从 Viewpager 中删除页面/片段的功能,我尝试将我的 FragmentPageAdapter 更改为 FragmentStatePageAdapter 并覆盖我 getItemPosition()
的 to return POSITION_NONE;
但是这仍然不允许我删除我打电话时动态分段fragments.remove(page);
pageAdapter.notifyDataSetChanged();
以前有没有人成功地做到过?看起来应该很简单,但事实并非如此,下面是我的片段适配器,任何帮助都会大有帮助,谢谢!
class MyPageAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragments;
public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public float getPageWidth(int position) {
if (position == 0) {
return (0.75f);
} else {
return (1f);
}
}
@Override
public CharSequence getPageTitle(int position) {
MyFragment theFragment = (MyFragment) this.fragments.get(position);
return theFragment.returnTitle();
}
@Override
public int getCount() {
return this.fragments.size();
}
}