ShamylZakariya / StickyHeaders

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.
MIT License
1.4k stars 185 forks source link

Getting IndexOutOfBoundsException - adapterPosition cannot be > getItemCount() on Android 7 #82

Closed charuraninag closed 5 years ago

charuraninag commented 6 years ago

Fatal Exception: java.lang.IndexOutOfBoundsException: adapterPosition (8) cannot be > getItemCount() (8)at org.zakariya.stickyheaders.b.a(SectioningAdapter.java:1198)at org.zakariya.stickyheaders.b.p(SectioningAdapter.java:1244)at org.zakariya.stickyheaders.StickyHeaderLayoutManager.q(StickyHeaderLayoutManager.java:840)at org.zakariya.stickyheaders.StickyHeaderLayoutManager.f(StickyHeaderLayoutManager.java:660)at org.zakariya.stickyheaders.StickyHeaderLayoutManager.h(StickyHeaderLayoutManager.java:721)at org.zakariya.stickyheaders.StickyHeaderLayoutManager.c(StickyHeaderLayoutManager.java:176)

gosoares commented 6 years ago

I'm having the same issue, it happens when i delete the last itens from the last section, and call notifySectionDataSetChanged(index)

baiguangyuan commented 6 years ago

Call notifySectionItemRemoved(sectionIndex, itemIndex) method instead of notifySectionDataSetChanged(index)

   /**
     * Notify that an item has been removed from a section
     * Never directly call notifyItemRemoved
     *
     * @param sectionIndex index of the section
     * @param itemIndex    index of the item in the section where 0 is the first position in the section
     */
    public void notifySectionItemRemoved(int sectionIndex, int itemIndex)
AlBlanc commented 5 years ago

Hello! I have made a fork and solved the issue -> https://github.com/Sportner/StickyHeaders