donkingliang / GroupedRecyclerViewAdapter

GroupedRecyclerViewAdapter可以很方便的实现RecyclerView的分组显示,并且每个组都可以包含组头、组尾和子项;可以方便实现多种Type类型的列表,可以实现如QQ联系人的列表一样的列表展开收起功能,还可以实现头部悬浮吸顶功能等。
Apache License 2.0
1.65k stars 216 forks source link

插入多个分组问题 #86

Closed w296365959 closed 2 years ago

w296365959 commented 2 years ago

阅读后发现 notifyGroupRangeInserted 库中提供的插入多个分组数据时,是否定位错误 在for循环中使用hasHeader(i) ,hasFooter ,getChildrenCount目前的i位置错误,根据i无法确定对应分组数据问题 以下是库中方法 ` public void notifyGroupRangeInserted(int groupPosition, int count) { ArrayList list = new ArrayList<>(); for (int i = 0; i < count; i++) { GroupStructure structure = new GroupStructure(hasHeader(i), hasFooter(i), getChildrenCount(i)); list.add(structure); }

    if (groupPosition < mStructures.size()) {
        mStructures.addAll(groupPosition, list);
    } else {
        mStructures.addAll(list);
        groupPosition = mStructures.size() - list.size();
    }

    int index = countGroupRangeItem(0, groupPosition);
    int itemCount = countGroupRangeItem(groupPosition, count);
    if (itemCount > 0) {
        notifyItemRangeInserted(index, itemCount);
    }
}`
donkingliang commented 2 years ago

确实,组下标错了,应该是groupPosition+i;groupPosition是插入的开始位置