Uncheck one box unchecks all boxes

47 views Asked by At

I have an activity that extends PreferenceActivity. I have in settings.xml 3 checkboxpreferences. If I uncheck the first checkbox, the other 2 to uncheck. What is the code for that?

1

There are 1 answers

0
moffeltje On

I think you want to use checkbox.toggle()

First make a onClickListener:

Checkbox chk = (CheckBox)findViewById(R.id.checkBox1);

chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

       @Override
       public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

       }
   }
); 

Then change the other checkboxes:

    CheckBox chk1, chk2;

        chk1 = (CheckBox)findViewById(R.id.checkBox2);
        chk2 = (CheckBox)findViewById(R.id.checkBox3);

and:

            if(chk1.isChecked()){
                chk1.toggle();
            }

            if(chk2.isChecked()){
                chk2.toggle();
            }