I have an array list that contains all the checked items and a hashset to prevent duplications. But now I have a problem that the array list still stores the previously checked items even though i have unchecked it.
I have looked for solutions like Hashset and using (!isChecked) but those wont delete the previously stored value.
viewHolder.checkBox.setTag(dataModel.getChkBool());
viewHolder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (viewHolder.checkBox.isChecked()) {
citiesSelection.add("\n" + dataModel.getCity());
}
//prevent duplicates
hashSet.addAll(citiesSelection);
citiesSelection.clear();
citiesSelection.addAll(hashSet);
Toast.makeText(getContext(), "Checked Total: " + citiesSelection, Toast.LENGTH_LONG).show();
}
});
Screenshots:
Unchecked, but the arraylist still contains the previously checked ones
Aucun commentaire:
Enregistrer un commentaire