我在点击活动中的项目时创建适配器。第一页是空的。当我滑过它(到第三页内容存在)并且回来内容就在那里。
public void showItem(){
mSwipeAdapter = new SwipeAdapter(mItemsList);
mSwipePager.setAdapter(mSwipeAdapter);
this.setVisibility(View.VISIBLE);
}
和适配器
private class SwipeAdapter extends PagerAdapter {
List<Item> mSwipeItems;
public SwipeAdapter(List<Item> mItems) {
mSwipeItems = mItems;
}
@Override
public int getCount() {
return mSwipeItems.size();
}
public Object instantiateItem(ViewGroup collection, int position) {
mCurrentContentView = new ContentView(mContext);
mCurrentItem = mSwipeItems.get(position);
mCurrentContentView.showItem(mCurrentItem);
collection.addView(mCurrenContentView);
return mCurrentContentView;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
}
我在这里发现同样的问题First viewpager page blank,但没有解决方案。