My code below works perfect when the activity loads with all checkboxes checked, or all checkboxes unchecked, and they are checked or unchecked from that point on, but the problem is that in reality the activity might load with SOME checkboxes checked.
I suppose the key is count = 0;
If I could set count
to the number of checked boxes when the form loads...
This is what I have in the setOnClickListener(new View.OnClickListener() {
of my adapter
, works for when all checkboxes start from a checked or unchecked position:
//we want to keep track of checked boxes
int count;
count = 0;
int size = MatchingContactsAsArrayList.size();
for (int i = 0; i < size; i++) {
if (theContactsList.get(i).isSelected) {
count++;
}
}
if (count == 0) {
Toast.makeText(context_type, "count is 0!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context_type, "The count is " + count, Toast.LENGTH_SHORT).show();
}