StickyHeaders icon indicating copy to clipboard operation
StickyHeaders copied to clipboard

notifySectionRemoved has a bug

Open BraisGabin opened this issue 7 years ago • 2 comments

I want to remove the last 5 sections in my adapter. Let's say from index 15 to index 19.

The first call I do adapter.notifySectionRemoved(19) works great. But when I call adapter.notifySectionRemoved(18) I have this stack trace:

Caused by: java.lang.IndexOutOfBoundsException: Invalid index 18, size is 15
   at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
   at java.util.ArrayList.get(ArrayList.java:308)
   at org.zakariya.stickyheaders.SectioningAdapter.notifySectionRemoved(SectioningAdapter.java:995)
   at com.example.Adapter$1.onRemoved(Adapter.java:227)
   at android.support.v7.util.BatchingListUpdateCallback.dispatchLastEvent(BatchingListUpdateCallback.java:62)
   at android.support.v7.util.BatchingListUpdateCallback.onChanged(BatchingListUpdateCallback.java:117)
   at android.support.v7.util.DiffUtil$DiffResult.dispatchUpdatesTo(DiffUtil.java:722)
   at com.example.Adapter.setData(Adapter.java:216)

The problem is that after the first notifySectionRemoved the Adapter recreates the ArrayList<Section> sections array from scratch. Using the current info provided with the adapter.

BraisGabin avatar May 24 '17 13:05 BraisGabin

Problem solved here -> https://github.com/Sportner/StickyHeaders

but i am still having a similar issue, I am on it

AlBlanc avatar Nov 22 '18 16:11 AlBlanc

I wrote my own LayoutManager: https://github.com/21Buttons/sticky-headers

We are using it in production and works perfectly. I don't know why I didn't write a proper documentation for it... I'll try to write it next week.

BraisGabin avatar Nov 23 '18 09:11 BraisGabin