lightSky / InfiniteIndicator

This lib can be used for viewpager infinite loop with indicator easily.
486 stars 102 forks source link

The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! #10

Closed Jack-Xiao closed 8 years ago

Jack-Xiao commented 9 years ago

你好,使用该库有时会发生如题错误: 发生该错误的机型有:MI 4LTE ,HM NOTE 1S, MI 3W。操作系统均为 android 4.4.4 下面是详细报错: java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 1300, found: 1200 Pager id: com.louie.luntonghui:id/view_pager Pager class: class android.support.v4.view.ViewPager Problematic adapter: class cn.lightsky.infiniteindicator.indicator.RecyleAdapter 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.layout(View.java:14832) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.widget.ScrollView.onLayout(ScrollView.java:1468) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) at android.widget.FrameLayout.onLayout(FrameLayout.java:388) at android.view.View.layout(View.java:14845) at android.view.ViewGroup.layout(ViewGroup.java:4631) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2026) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1783) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1039) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5648) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5047) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method)

lightSky commented 9 years ago

具体的情景是怎样的呢?比如某个图片加载失败,或者横竖屏切换,或者你手动去删除某个Item等

Jack-Xiao commented 9 years ago

是直接使用在App 首页某fragment中的轮播图。 在onCreateView某方向异步取得数据然后调用: for (int i = 0; i < list.size(); i++) { DefaultSliderView textSliderView = new DefaultSliderView(mContext); Log.d("imag..", list.get(i) + "..."); textSliderView .image(list.get(i)) // 后台传过来的图片url .setScaleType(BaseSliderView.ScaleType.Fit) .showImageResForEmpty(R.drawable.default_image_in_no_source) .showImageResForError(R.drawable.default_image_in_no_source); mAnimCircleIndicator.addSlider(textSliderView); } mAnimCircleIndicator.setIndicatorPosition(InfiniteIndicatorLayout. IndicatorPosition.Center_Bottom); mAnimCircleIndicator.startAutoScroll();

然后在该fragment 的onDestoryView调用
@Override public void onDestroyView() { super.onDestroyView(); mAnimCircleIndicator.stopAutoScroll(); ButterKnife.reset(this); }

1)我遇见的情况是(偶尔)在首次进入App轮播图的时候出现 。 2)有在stackoverflow中查到也有人出现这种情况,“ The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!” 然而还是不知道是什么原因造成的,因为你的内部都有调用notifyDataSetChanged. 希望能帮忙尽情解决。

Jack-Xiao commented 9 years ago

我遇见的情况之一是: 在图片未加载出来, 然后进行手滑动快速切换到之后的图片。
其实不是很明白为什么getCount 方向要写成
@Override public int getCount() { return isLoop ? getRealCount() * 100 : getRealCount(); } 这样,恩, 我比较菜, 不明白。

lightSky commented 9 years ago

是为了得到一个较大的数,以便可以较长时间的轮循,而getView中处理的时候是取余的

lightSky commented 9 years ago

另外你应该在onPause 和 onResume中进行stop 和 start,这样比较节省资源

Jack-Xiao commented 9 years ago

喔,那这Issue的呢? 它是可以重现的。

lightSky commented 9 years ago

你QQ多少,我加你一下

lightSky commented 8 years ago

1.1.0发布了,而且支持自动更新了,ImageLoader自定义,api也更方便,欢迎使用和反馈