应用程序的PagerAdapter在不调用PagerAdapter#notifyDataSetChanged的情况下更改了适配器的内容

时间:2016-06-23 06:33:07

标签: android fragmentpageradapter

我想在我的视图寻呼机中调用寻呼机适配器,所以下面是我的代码

public class MyFragmentSimilarPagerAdapter extends FragmentPagerAdapter {

ArrayList<GetProductDetail.SimilarProductDetailData> list;
LinearLayout mLinearLayout;

@Override
public int getItemPosition(Object object) {
    return POSITION_NONE;
}
public MyFragmentSimilarPagerAdapter(FragmentManager fm, ArrayList<GetProductDetail.SimilarProductDetailData> list, LinearLayout mLinearLayout ) {
    super(fm);
    this.list=list;
    this.mLinearLayout=mLinearLayout;
}


@Override
public Fragment getItem(int arg0) {

    MyFragment myFragment = new MyFragment(mLinearLayout);
    Bundle data = new Bundle();
    Log.d("PRID AT",list.get(arg0).getId());
    data.putString("prid", list.get(arg0).getSlug());
    myFragment.setArguments(data);
    return myFragment;
}

/** Returns the number of pages */

@Override
public int getCount() {

    return list.size();

}

@Override
public CharSequence getPageTitle(int position) {
    return "Page #" + ( position + 1 );
   }

}

从我的活动类

中调用此适配器
        FragmentManager fm = getSupportFragmentManager();
    mAdapter = new MyFragmentSimilarPagerAdapter(fm, Tags.mArrayListSimilarProduct,mLinearLayoutBottom);
    mViewPager.setAdapter(mAdapter);

当我运行此代码时,我得到错误,如 java.lang.IllegalStateException:应用程序的PagerAdapter更改了适配器的内容而不调用PagerAdapter#notifyDataSetChanged 任何想法如何解决这个问题?你的所有建议都很明显

Logcat输出

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 2, found: 3 Pager id: com.shopping.addtobuy:id/vpPager Pager class: class android.support.v4.view.ViewPager Problematic adapter: class adapter.MyFragmentSimilarPagerAdapter
 at android.support.v4.view.ViewPager.populate(ViewPager.java:999)
 at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
 at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1473)
 at android.view.View.measure(View.java:15172)
 at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
 at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
 at android.view.View.measure(View.java:15172)
 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
 at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
 at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:15172)

0 个答案:

没有答案