ayalma / ExpandableRecyclerView

implemention of ExpandableRecyclerView for android
24 stars 8 forks source link

java.lang.IndexOutOfBoundsException: Invalid index 6 size is 6 #5

Open sonvp opened 7 years ago

sonvp commented 7 years ago

Hi @ayalma . I test it with your demo and I add Log in method getGroupItem(int position). I receive bug with Log below 06-09 16:33:03.516 18316-18316/ayalma.ir.sample D/getGroupItem: 0 06-09 16:33:03.521 18316-18316/ayalma.ir.sample D/getGroupItem: 1 06-09 16:33:03.521 18316-18316/ayalma.ir.sample D/getGroupItem: 2 06-09 16:33:03.526 18316-18316/ayalma.ir.sample D/getGroupItem: 3 06-09 16:33:03.526 18316-18316/ayalma.ir.sample D/getGroupItem: 4 06-09 16:33:03.526 18316-18316/ayalma.ir.sample D/getGroupItem: 5 06-09 16:33:03.531 18316-18316/ayalma.ir.sample D/getGroupItem: 6

704480904 commented 5 months ago

@Override public int getItemViewType(int i) { int group = 0; while (group <= getGroupItemCount()) { if (i > 0 && !isExpanded(group)) { i--; group++; continue; } if (i > 0 && isExpanded(group)) { i--; if (i < getChildItemCount(group)) return getChildItemViewType(group, i); i -= getChildItemCount(group); group++; continue; } if (i == 0) return TYPE_HEADER; } throw new IndexOutOfBoundsException();

应该是是因为添加了一个header 导致