Closed qiushihang closed 4 years ago
重复出现item是什么意思?是item重复了吗?
看一下你的adapter复写GroupedRecyclerViewAdapter里的方法有没有正确
是item 重复出现了,第一次加载显示是没问题的,滚动后,再滚动回来就发现有重复的item出现了
@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;
}
@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;
}
}
你的ChildViewType和HeaderViewType有重复吗?比如HeaderViewType中有1,ChildViewType就不能有1。所有的type都不能出现重复。
嗯嗯,type 数字有重复,改成不一致的就ok 了,多谢多谢
上下滑动后,发现会重复出现item,