vendredi 22 juillet 2016

How To handle Recyclerview state With checkboxes?

i am working with recyclerview . my recyclerview is populated from list and it has both states of checkbox after populating .but i have some problem when i checked or unchecked in specific position and after scrolling its still on their previous position. My code is shown below.

@Override

public void onBindViewHolder(final AttendanceHolder holder, final int position) {


    holder.statusCheckBox.setOnCheckedChangeListener(null);
    if(childrenListForAttendance.get(position).getStatus()==0) {
        holder.statusCheckBox.setTag(childrenListForAttendance.get(position));
        holder.childName.setText(childrenListForAttendance.get(position).getMchildName());
        holder.statusCheckBox.setChecked(childrenListForAttendance.get(position).isSelected());
    }
    else{
        holder.statusCheckBox.setTag(childrenListForAttendance.get(position));
        holder.childName.setText(childrenListForAttendance.get(position).getMchildName());
        holder.statusCheckBox.setChecked(false);
    }

    holder.statusCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            childrenListForAttendance.get(position).setIsSelected(isChecked);
        }
    });

}

    @Override
    public int getItemCount()

    {
        return childrenListForAttendance.size();
    }

How to handle this situation . thanks in advance.




Aucun commentaire:

Enregistrer un commentaire