donkingliang / GroupedRecyclerViewAdapter

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

作者大大,使用后,上下滑动,发现item没做缓存啊。 #47

Closed qiushihang closed 4 years ago

qiushihang commented 4 years ago

上下滑动后,发现会重复出现item,

donkingliang commented 4 years ago

重复出现item是什么意思?是item重复了吗?

donkingliang commented 4 years ago

看一下你的adapter复写GroupedRecyclerViewAdapter里的方法有没有正确

qiushihang commented 4 years ago

是item 重复出现了,第一次加载显示是没问题的,滚动后,再滚动回来就发现有重复的item出现了

qiushihang commented 4 years ago
@Override
public int getHeaderLayout(int viewType) {
    switch (viewType) {
        case ConstantsHelp
                .HOME_CONTENT_TYPE.GROUP.ITEM_STICK_TOP:
            return R.layout.main_item_sticky_top;
        case ConstantsHelp
                .HOME_CONTENT_TYPE.GROUP.ITEM_LABEL:
            return R.layout.main_item_list_type;
    }
    return 0;
}

@Override
public int getFooterLayout(int viewType) {
    return 0;
}

@Override
public int getChildViewType(int groupPosition, int childPosition) {
    return mGroups.get(groupPosition).getChildren().get(childPosition).getChildType();
}

@Override
public int getChildLayout(int viewType) {
    switch (viewType) {
        case ConstantsHelp
                .HOME_CONTENT_TYPE.CHILD.ITEM_HOMEWORK:
            return R.layout.item_homework_hor_rv;
        case ConstantsHelp
                .HOME_CONTENT_TYPE.CHILD.ITEM_CLASS_COURSE:
            return R.layout.main_item_course;
        case ConstantsHelp
                .HOME_CONTENT_TYPE.CHILD.ITEM_COURSE_RECOMMEND:
            return R.layout.main_item_course_recommend;
    }
    return 0;
}
qiushihang commented 4 years ago

@Override public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) { //HomeGroupBean groupBean = mGroups.get(groupPosition); }

@Override
public void onBindChildViewHolder(BaseViewHolder holder, int groupPosition, int childPosition) {
    HomeChildBean childBean = mGroups.get(groupPosition).getChildren().get(childPosition);
    int childType = childBean.getChildType();

    switch (childType) {
        case ConstantsHelp.HOME_CONTENT_TYPE.CHILD.ITEM_HOMEWORK://课后作业
            List<HomeWorkItemBean> homeWorkList = childBean.getHomeWorkList();
            HomeWorkHorAdapter homeWorkHorAdapter = new HomeWorkHorAdapter(mContext);
            homeWorkHorAdapter.setNewData(homeWorkList);
            LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
            layoutManager.setOrientation(RecyclerView.HORIZONTAL);
            ByRecyclerView recyclerView = holder.get(R.id.homework_hor_rv);
            recyclerView.setLayoutManager(layoutManager);

            HashMap<String, Integer> hashMap = new HashMap<>();
            int horSpc = mContext.getResources().getDimensionPixelSize(R.dimen.main_homework_item_hor_space);
            hashMap.put(SimpleSpaceDecoration.LEFT_SPACE, horSpc);
            recyclerView.addItemDecoration(new SimpleSpaceDecoration(hashMap));
            recyclerView.setAdapter(homeWorkHorAdapter);
            break;

        case ConstantsHelp.HOME_CONTENT_TYPE.CHILD.ITEM_CLASS_COURSE: //班级课程
            ClassCourseItemBean itemBean = childBean.getClassCourseItemBean();
            View itemView = holder.itemView;
            ImageView coverImage = holder.get(R.id.class_course_icon);
            TextView titleTv = holder.get(R.id.class_course_title);
            TextView subTitleTv = holder.get(R.id.class_course_sub_title);

            if (isViewValid(coverImage, titleTv, subTitleTv)) {
                titleTv.setText(itemBean.getUnit_name());
                subTitleTv.setText(itemBean.getDesc());

                int radius = mContext.getResources().getDimensionPixelSize(R.dimen.home_content_item_icon_radius);
                GlideUtils.setImgCorn(mContext, itemBean.getCoverImage(), coverImage, radius);
            }
            break;
        case ConstantsHelp.HOME_CONTENT_TYPE.CHILD.ITEM_COURSE_RECOMMEND: //推荐课程
            RecommendInfoBean bean = childBean.getRecommendInfoBean();
            ImageView imageView = holder.get(R.id.recommend_course_icon);
            TextView title = holder.get(R.id.recommend_course_title);
            TextView subTitle = holder.get(R.id.recommend_course_sub_title);

            if (isViewValid(imageView, title, subTitle)) {
                title.setText(bean.getUnit_name());
                subTitle.setText(bean.getSubject());

                int round = mContext.getResources().getDimensionPixelSize(R.dimen.home_content_item_icon_radius);
                GlideUtils.setImgCorn(mContext, bean.getCoverImage(), imageView, round);
            }
            break;
    }

}
donkingliang commented 4 years ago

你的ChildViewType和HeaderViewType有重复吗?比如HeaderViewType中有1,ChildViewType就不能有1。所有的type都不能出现重复。

qiushihang commented 4 years ago

嗯嗯,type 数字有重复,改成不一致的就ok 了,多谢多谢