In DeleteTask, I have a button used to delete the list which checkbox is checked.
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int itemCount = listview.getCount();
for (int i = itemCount - 1; i >= 0; i--) {
SearchList search = adapter.getItem(i);
if (search.isSelected()) {
adapter.removeItem(i);
delete.setText("DELETE");
counter=0;
}
}
}
});
In DeleteAdapter, it has a counter used to count the checked box and display the counter in button
. Once the button
is clicked, the counter will reset to 0 and only shows DELETE
in button setText.
holder.ckbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
int getPosition = (Integer) v.getTag(); // Here we get the position that we have set for the checkbox using setTag.
search.get(getPosition).setSelected(((CheckBox)v).isChecked()); // Set the value of checkbox to maintain its state.
checkBoxCounter ++;
delete.setText("DELETE"+""+"("+ checkBoxCounter +")");
} else
{
int getPosition = (Integer) v.getTag(); // Here we get the position that we have set for the checkbox using setTag.
search.get(getPosition).setSelected(((CheckBox) v).isChecked()); // Set the value of checkbox to maintain its state.
checkBoxCounter--;
if (checkBoxCounter == 0) {
delete.setText("DELETE");
}
else {
delete.setText("DELETE" + "" + "(" + checkBoxCounter + ")");
}
}
}
});
My problem now is when the delete button is clicked, it show 'DELETE', but when I check the checkBox, the counter did not reset. How to reset the counter ?
Aucun commentaire:
Enregistrer un commentaire