android控件ViewPager动态添加删除一条数据

private List<String> mPathList;
private FragmentStatePagerAdapter mPagerAdapter;

//1.使用FragmentStatePagerAdapter mPagerAdapter
= new FragmentStatePagerAdapter(getSupportFragmentManager()) { @Override public int getCount() { return mPathList.size(); } @Override public Fragment getItem(int i) { return PhotoPreviewFragment.newInstance(mPathList.get(i)); } @Override public int getItemPosition(Object object) {
      //2.重写getItemPostman方法返回POSITION_NONE,这样添加或者删除数据后刷新才有效
return PagerAdapter.POSITION_NONE; } }; mViewPager.setAdapter(mPagerAdapter);

int currentItem = mViewPager.getCurrentItem();
mPathList.remove(currentItem);
mPagerAdapter.notifyDataSetChanged();
 

 

posted @ 2019-02-19 11:09  yongfengnice  阅读(1153)  评论(0编辑  收藏  举报