我有一个奇怪的问题:我有一个带有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)
我无法解释原因,以及哪些代码在这里会有所帮助......
它总是不会发生,有时只会发生