我想在每個頁面的不同數據的四頁viewpager中添加一個listview。 Vector pages = new Vector();在viewpager中使用listview的問題?
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);
}
}
});
}
,這裏是適配器類 公共類CustomPagerAdapter擴展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()。任何想法請!!!!! 現在我改變了它與四個listview ....它只顯示三頁!!!哪裏是第四個?如果pagerviewer一次只能保存三頁如何刪除第四個位置上的第一個,反之亦然?
同樣的錯誤! – user2696228
首先它顯示第一頁的數據,並在滑動頁面上崩潰......但現在它不顯示任何東西,也不強制關閉。 – user2696228