Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notifyDataSetChanged会崩 #14

Closed
maplejaw opened this issue May 23, 2016 · 3 comments
Closed

notifyDataSetChanged会崩 #14

maplejaw opened this issue May 23, 2016 · 3 comments

Comments

@maplejaw
Copy link

maplejaw commented May 23, 2016

比如说,刚开始的广告有4页,刷新后只有1页时.只要上次的广告停留的不是第一页,刷新后不仅图片没有刷新,而且必崩。提示信息如下

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 4, found: 1 Pager id: com.zhipu.salehelper.referee:id/viewpager_inner Pager class: class android.support.v4.view.ViewPager Problematic adapter: class com.zhipu.salehelper.referee.adapter.HomeLooperAdapter
                                                                                  at android.support.v4.view.ViewPager.populate(ViewPager.java:1000)
                                                                                  at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:552)
                                                                                  at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:514)
                                                                                  at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:495)
                                                                                  at com.zhipu.salehelper.referee.widget.rollviewpager.RollPagerView$TimeTaskHandler.handleMessage(RollPagerView.java:133)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                                  at android.os.Looper.loop(Looper.java:194)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5549)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)

可以看出at com.zhipu.salehelper.referee.widget.rollviewpager.RollPagerView$TimeTaskHandler.handleMessage(RollPagerView.java:133)这一行崩的。
刷新代码如下

bannerList.clear();
bannerList.addAll(list);
mLooperAdapter.notifyDataSetChanged();
@Jude95
Copy link
Owner

Jude95 commented May 23, 2016

贴一下你的Adapter代码?我测试很正常。

@maplejaw
Copy link
Author

我刚刚在我fork的代码里,写了个demo。还是有这个问题。
而且还发现,只有切换为一张图片时,居然发生了ANR。
你跑跑试试,不知道是不是我使用的姿势不对。
git@github.com:maplejaw/RollViewPager.git

@Jude95
Copy link
Owner

Jude95 commented May 24, 2016

确实是LoopPagerAdapter的BUG。已解决。试试1.3.1。看看还有问题没

ANR的原因真是...找了半天,发现是我的循环是用MAX_INT的页数实现的,一开始就设当前页为MAX_INT/2,1张的时候页数变为1.(因为某个用户提issue说1页的时候不应该能左右滑)
于是ViewPager就从MAX_INT/2跑回到第1页.路程太长根本停不下来~~
对于解决办法,我只有这样解决了。重置ViewPager。

@Override
public void notifyDataSetChanged() {
    mViewList.clear();
    mViewPager.getViewPager().setAdapter(this);
    super.notifyDataSetChanged();
}

@Jude95 Jude95 closed this as completed Jun 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants