vendredi 3 avril 2015

How to make all checkboxes unchecked with a certain condition? Android

I have 45 check boxes that you can check. What I want to do is if you try to select more than 6 check boxes it will automatically disable all the buttons, however, if you tap the even one of the checked checkbox ,it will make all the checkbox checkable. This sounds simple ,but I cannot implements this method. I would be grateful if the pros here can help a noob like me. Here is the sample code.



checkbox[i].setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) { buttonView.setTextColor(Color.GREEN);

buttonClicked.add(buttonView.getText().toString());
buttonView.setTextSize(18);

count+=1;

if(count>=6){

for(int i = 0; i< 43;i++){

checkbox[i].setEnabled(false);
stopped = checkbox[i].isChecked();
if(stopped==true){
for(int a = 0; a < checkbox.length;a++){
checkbox[a].setEnabled(true);
}
}



}

}
}
if (!isChecked) {buttonView.setTextColor(Color.BLACK);

buttonClicked.remove(buttonView.getText().toString());
buttonView.setTextSize(15);
count-=1;

Aucun commentaire:

Enregistrer un commentaire