Unten ist der my-Code.Duplizierung in Checkbox-Auswahl in RecyclerView
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 ist, wenn ich ein checkBox
einschließlich checkBox
einige andere checkBox
im RecyclerView
wird geprüft wählen. Aber wenn ich einchecke adapter
Artikel wurde richtig hinzugefügt, aber checkBox
Auswahl werden verdoppelt.
Bsp: Wenn ich den ersten Artikel checkBox
überprüfte und nach unten scrolle, werden auch 16 Artikel checkBox
geprüft. Wenn Sie das Kontrollkästchen checkBox
deaktivieren, wird auch das erste Element deaktiviert.
Dank mate. Es funktioniert. –
Ihre herzlichsten :) – Anonymous