我想在 viewpager 的四个页面中添加一个列表视图,每个页面都有不同的数据。矢量页面 = 新矢量();
pages.add(listAppStore1);
pages.add(listAppStore2);
pages.add(listAppStore3);
pages.add(listAppStore4);
ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
CustomPagerAdapter adapter = new CustomPagerAdapter(AppsActivity.this,pages);
vp.setAdapter(adapter);
vp.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
public void onPageScrolled(int arg0, float arg1, int position) {
// TODO Auto-generated method stub
}
public void onPageScrollStateChanged(int position1) {
// TODO Auto-generated method stub
if (position1==0) {
modifydata();
myAppStore.setadapter(mStoreAdapter);
} else if (position1==1) {
modifydata();
myAppStore.setadapter(mStoreAdapter);
}else if (position1==2) {
modifydata();
myAppStore.setadapter(mStoreAdapter);
}else if (position1==3) {
modifydata();
myAppStore.setadapter(mStoreAdapter);
}
}
});
}
这是适配器类 public class CustomPagerAdapter extends PagerAdapter {
private Context mContext;
private Vector<View> pages;
public CustomPagerAdapter(Context context, Vector<View> pages) {
this.mContext=context;
this.pages=pages;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View page = pages.get(position);
container.addView(page);
return page;
}
@Override
public int getCount() {
return 3;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
强制关闭后我在 logcat 中收到错误指定的孩子已经有父母。您必须首先在孩子的父母上调用 removeView()。请有任何想法!!!!现在我用四个列表视图改变了它....它只显示了三页!!!第四页在哪里?如果pagerviewer 一次只保存三页,如何删除第四个位置的第一页,反之亦然????