android viewpager 删除子项

viewpager 删除子项:

1、adapter

首先自定义adapter继承PagerAdapter并实现下列方法

 public List views;
@Override
	public int getCount() {
		if(views != null){
			return views.size();
		}
		return 0;
	}


	@Override
	public void destroyItem(View container, int position, Object view) {
		View delView=(View)view;
		((ViewPager) container).removeView(delView);
	}

	@Override
	public Object instantiateItem(View container, int position) {
		((ViewPager) container).addView(views.get(position));
		return views.get(position);
	}
	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0==arg1;
	}
2、activity里面要做的是

	adapter.destroyItem(mViewPage, mPosition, tempView);
	adapter.views.remove(delPosition);
	adapter.notifyDataSetChanged ();

这样就可以了

你可能感兴趣的:(android viewpager 删除子项)