0

我在活动中单击项目时创建适配器。第一页是空的。当我将它滑过(到第三页内容时)并回来时内容就在那里。

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空白但没有解决方案。

4

0 回答 0