mardi 16 juin 2015

Android One CheckBox Selected at a time issue

I have a list with items that have checkBox, and I need that only one checkBox to be selected at a time. I cannot use listView with singleChoice nor RadioButtons. Below is my code I am using but I do not know why is not working.

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (selectedCheckBox != null) {
        // simulate radio group behavior
        selectedCheckBox.setChecked(false);
        selectedCheckBox = null;
    }

    if (isChecked) {
        selectedCheckBox = (CheckBox) buttonView;
    }
}

The problem is that the checkBoxes still remain checked and I do not know why regarding that I set the previous selectedCheckBox to false. Could anyone explain what happens? Thanks




Aucun commentaire:

Enregistrer un commentaire