Below is the my code.
holder.followDiseaseCheckBox.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View view) {
if (holder.followDiseaseCheckBox.isChecked()) {
holder.followDiseaseCheckBox.setChecked(true);
checkBoxClicked++;
holder.followDiseaseCheckBox.setChecked(true);
// for Follow.
if (isFollowOrUnFollow.equals("FOLLOW")) {
((FollowActivity) context).diseaseListFromAdapter.add(String.valueOf(diseaseMap.get("id")));
((FollowActivity) context).setFollowButton(true);
}
// for Unfollow.
else if (isFollowOrUnFollow.equals("UN_FOLLOW")) {
((FollowTwoActivity) context).unFollowedDiseaseListFromAdapter.add(String.valueOf(diseaseMap.get("id")));
((FollowTwoActivity) context).setUnFollowDiseaseButton(true);
}
} else {
holder.followDiseaseCheckBox.setChecked(false);
checkBoxClicked--;
holder.followDiseaseCheckBox.setChecked(false);
// for Follow.
if (isFollowOrUnFollow.equals("FOLLOW")) {
((FollowActivity) context).diseaseListFromAdapter.remove(String.valueOf(diseaseMap.get("id")));
}
// for Unfollow.
else if (isFollowOrUnFollow.equals("UN_FOLLOW")) {
((FollowTwoActivity) context).unFollowedDiseaseListFromAdapter.remove(String.valueOf(diseaseMap.get("id")));
}
if (checkBoxClicked == 0) {
// for Follow.
if (isFollowOrUnFollow.equals("FOLLOW")) {
((FollowActivity) context).setFollowButton(false);
((FollowActivity) context).diseaseListFromAdapter.clear();
}
// for Unfollow.
else if (isFollowOrUnFollow.equals("UN_FOLLOW")) {
((FollowTwoActivity) context).setUnFollowDiseaseButton(false);
((FollowTwoActivity) context).unFollowedDiseaseListFromAdapter.clear();
}
}
}
}
});
Problem is When i select a checkbox including that checkbox some other checkbox in the RecyclerView gets checked. But when i check in diseaseListFromAdapter ArrayList item got added properly but checkbox selection are getting duplicated. Ex: If i checked first item checkbox and scroll down 16th items checkbox will also be checked. Unchecking that checkbox will uncheck the first item as well.
Aucun commentaire:
Enregistrer un commentaire