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 adapter
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.