I have a button that says Select All. When clicked all the check boxes in my listview should become checked. The same button changes text to Clear All. When clicked all the checkboxes should become unchecked and the text turns back to Select All....
In my listview however, it's every second button that becomes checked or unchecked.
When Select All is clicked, checkbox 1, 3 and 5 become checked. Checkbox 2 and 4 become unchecked. text turns to Clear All.
When Clear All is clicked, checkbox 1, 3 and 5 become unchecked. Checkbox 2 and 4 become checked. text turns to Select All.
I can't see what's wrong with my code. Or maybe it's something in another part of my app but there's no errors or warnings, not sure where to start debugging. Thanks.
btnCheckAll.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int count = MatchingContactsAsArrayList.size();
for (int i = 0; i < count; i++) {
LinearLayout itemLayout = (LinearLayout) listView.getChildAt(i); // Find by under LinearLayout
CheckBox checkbox = (CheckBox) itemLayout.findViewById(R.id.checkBoxContact);
if(btnCheckAll.getText().toString().equalsIgnoreCase("Select All")) {
checkbox.setChecked(true);
btnCheckAll.setText("Clear All");
}
else if (btnCheckAll.getText().toString().equalsIgnoreCase("Clear All")){
checkbox.setChecked(false);
btnCheckAll.setText("Select All");
}}}});
Aucun commentaire:
Enregistrer un commentaire