I am facing a problem now that I really don't know what is going on.
First let me explain what I want to do. I am having a custom ListView that show my user detail and a checkbox beside it. At first, if I checked all the checkbox, the selectAll checkbox will not check on by itself.
Therefore, I have implemented the codes below. It works perfectly at first, but in the end I found out that if I have too much item that require me to scroll down, the system like detected that I have uncheck the checkbox and help me to deduct my "count".
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView == selectAll){
selectAll.setChecked(isChecked);
for(int i = 0; i < theList.size(); i++){
theList.get(i).setSelected(isChecked);
theList.get(i).setCheckAll(isChecked);
}
notifyDataSetChanged();
}else{
int position2 = (Integer) buttonView.getTag();
if(isChecked){
theList.get(position2).setSelected(true);
System.out.println("count here positions:"+ position2);
count++;
System.out.println("count here:"+ count);
if(count == theList.size())
{
selectAll.setChecked(true);
}
//String this_is_the_comment = theList.get(position2).getApprComments();
//System.out.println(this_is_the_comment);
}else{
theList.get(position2).setSelected(false);
count--; //when i scroll down the if condition will come to here
System.out.println("count here: -- "+count);
if (selectAll.isChecked()) {
selectAll.setChecked(false);
for (int i = 0; i < theList.size(); i++) {
theList.get(i).setSelected(true);
theList.get(position2).setSelected(false);
}
}
}
}
Please kindly help me with this bug. I am lost and stuck for 3 days.
Aucun commentaire:
Enregistrer un commentaire