Recyclerview changing items when is scrolled

后端 未结 6 788
一个人的身影
一个人的身影 2021-02-09 17:57

Can someone explain to me, what the problem is?

When I scroll down and then back to the top, my items were changed for other items in the list, and if I scroll again, th

6条回答
  •  粉色の甜心
    2021-02-09 18:25

    you define your item in wrong place, define your View inside of view holder and like below

    public static class AcademicVH extends RecyclerView.ViewHolder {
    private LinearLayout containerData;
    
    public AcademicVH(View itemView) {
        super(itemView);
        TextView txtSubject = (TextView) view.findViewById(R.id.txtSubjectValue);
        TextView txtGroup = (TextView) view.findViewById(R.id.txtGroupValue);
        TextView txtStatus = (TextView) view.findViewById(R.id.txtStatusValue);
        TextView txtFinalNote = (TextView) view.findViewById(R.id.txtFinalNoteValue);
        TextView txtYear = (TextView) view.findViewById(R.id.txtYearValue);
        containerData = (LinearLayout) itemView.findViewById(R.id.containerData);
        }
    }
    

    another trick, when you use condition (if) in your onBindViewHolder, you should complete it with (else).

提交回复
热议问题