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

How to update dotsIndicator adapter ? #55

Closed
manishpatelgt opened this issue Sep 10, 2019 · 6 comments
Closed

How to update dotsIndicator adapter ? #55

manishpatelgt opened this issue Sep 10, 2019 · 6 comments
Labels

Comments

@manishpatelgt
Copy link

manishpatelgt commented Sep 10, 2019

I don't see any notifyDataSetChanged() method that updates items in dotsIndicator adapter ?

When i add new item in my main viewpager adapter my app get crash. See below logs

10.09.19 14:57
Version: 1.0.43 (1043tackTrace)
Thread[main,5,main]
Exception: java.lang.ArrayIndexOutOfBoundsException
Message: length=10; index=-1
Stacktrace:
	java.util.ArrayList.get(ArrayList.java:439)
	com.tbuonomo.viewpagerdotsindicator.SpringDotsIndicator$buildOnPageChangedListener$1.onPageScrolled$viewpagerdotsindicator_release(SpringDotsIndicator.kt:161)
	com.tbuonomo.viewpagerdotsindicator.OnPageChangeListenerHelper.onPageScrolled(OnPageChangeListenerHelper.kt:17)
	com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator$setViewPager$2$addOnPageChangeListener$1.onPageScrolled(BaseDotsIndicator.kt:218)
	androidx.viewpager.widget.ViewPager.dispatchOnPageScrolled(ViewPager.java:1930)
	androidx.viewpager.widget.ViewPager.onPageScrolled(ViewPager.java:1904)
	androidx.viewpager.widget.ViewPager.pageScrolled(ViewPager.java:1842)
	androidx.viewpager.widget.ViewPager.completeScroll(ViewPager.java:1988)
	androidx.viewpager.widget.ViewPager.scrollToItem(ViewPager.java:692)
	androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:670)
	androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:631)
	androidx.viewpager.widget.ViewPager.dataSetChanged(ViewPager.java:1086)
	androidx.viewpager.widget.ViewPager$PagerObserver.onChanged(ViewPager.java:3097)
	androidx.viewpager.widget.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:291)
@tommybuonomo
Copy link
Owner

Hi @manishpatelgt,
You have to call the notifyDataSetChanged() on your adapter (the one linked to the view pager).
The dots will be refreshed automatically.

The reason of your crash is there is no item in your adapter. I'll fix this

@tommybuonomo
Copy link
Owner

@manishpatelgt Can you try again with the version 4.1.2 ?
Thanks

@manishpatelgt
Copy link
Author

@tommybuonomo Let me check with 4.1.2

@manishpatelgt
Copy link
Author

@tommybuonomo Yes it worked very well. Thanks for quick fixed

@OwaisKhatri
Copy link

OwaisKhatri commented Jul 6, 2021

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=10; index=-3 at java.util.ArrayList.get(ArrayList.java:439) at com.tbuonomo.viewpagerdotsindicator.DotsIndicator$buildOnPageChangedListener$1.onPageScrolled$viewpagerdotsindicator_release(DotsIndicator.java:107) at com.tbuonomo.viewpagerdotsindicator.OnPageChangeListenerHelper.onPageScrolled(OnPageChangeListenerHelper.java:22) at com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator$setViewPager$2$addOnPageChangeListener$1.onPageScrolled(BaseDotsIndicator.java:218)

I am still getting the same crash on 4.1.2.
What could be the fix for that? @tommybuonomo

@Stupidman22
Copy link

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=10; index=-3 at java.util.ArrayList.get(ArrayList.java:439) at com.tbuonomo.viewpagerdotsindicator.DotsIndicator$buildOnPageChangedListener$1.onPageScrolled$viewpagerdotsindicator_release(DotsIndicator.java:107) at com.tbuonomo.viewpagerdotsindicator.OnPageChangeListenerHelper.onPageScrolled(OnPageChangeListenerHelper.java:22) at com.tbuonomo.viewpagerdotsindicator.BaseDotsIndicator$setViewPager$2$addOnPageChangeListener$1.onPageScrolled(BaseDotsIndicator.java:218)

I am still getting the same crash on 4.1.2.
What could be the fix for that? @tommybuonomo

Hi, I have the same issue. Did you fix it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants