Android - notifyDataSetChanged导致"更改了适配器的内容而不调用notifyDataSetChanged"

时间:2015-10-21 09:41:13

标签: java android android-viewpager adapter notifydatasetchanged

我有一个奇怪的问题:我有一个带有FragmentPagerAdapter的View Pager。

更改了我的数据集中的一些内容后,我在适配器上调用了notifyDataSetChanged,然后我遇到了崩溃日志:

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 3, found: 2 Pager id: com.package:id/pager Pager class: class com.package.MyPager Problematic adapter: class com.package.MyAdapter
at android.support.v4.view.ViewPager.populate(ViewPager.java:967)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:555)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:913)
at android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2824)
at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:276)

我无法解释原因,以及哪些代码在这里会有所帮助......

它总是不会发生,有时只会发生

0 个答案:

没有答案