samedi 27 février 2016

.onCheckedListeners on multiple groups of checkboxes in Android Studio won't work

I have tried to have multiple groups of checkboxes where only one can be checked but on the attempt of implementing this functionality to a 2nd group of checkboxes the app crashes when i try to go to the activity containing those groups of checkboxes. The auton group of check boxes are working with only one able to be checked out of the 5 but even since I tried to add the same thing with the port_ ones I have had no luck.

    auton_nothing = (CheckBox)findViewById(R.id.nothing_cb);
    auton_touch= (CheckBox)findViewById(R.id.touchdefense_cb);
    auton_cross= (CheckBox)findViewById(R.id.cross_cb);
    auton_high= (CheckBox)findViewById(R.id.hg_cb);
    auton_low= (CheckBox)findViewById(R.id.lg_cb);

    auton_nothing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            auton_nothing.setChecked(b);
            auton_touch.setChecked(false);
            auton_cross.setChecked(false);
            auton_high.setChecked(false);
            auton_low.setChecked(false);
        }
    });
    auton_touch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            auton_nothing.setChecked(false);
            auton_touch.setChecked(b);
            auton_cross.setChecked(false);
            auton_high.setChecked(false);
            auton_low.setChecked(false);
        }
    });
    auton_cross.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            auton_nothing.setChecked(false);
            auton_touch.setChecked(false);
            auton_cross.setChecked(b);
            auton_high.setChecked(false);
            auton_low.setChecked(false);
        }
    });
    auton_high.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            auton_nothing.setChecked(false);
            auton_touch.setChecked(false);
            auton_cross.setChecked(false);
            auton_high.setChecked(b);
            auton_low.setChecked(false);
        }
    });
    auton_low.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            auton_nothing.setChecked(false);
            auton_touch.setChecked(false);
            auton_cross.setChecked(false);
            auton_high.setChecked(false);
            auton_low.setChecked(b);
        }
    });
    port_na= (CheckBox)findViewById(R.id.portc_na_cb);
    port_na.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            port_na.setChecked(b);
            port_attempt.setChecked(false);
            port_diff.setChecked(false);
            port_easy.setChecked(false);
        }
    });
    port_attempt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            port_na.setChecked(false);
            port_attempt.setChecked(b);
            port_diff.setChecked(false);
            port_easy.setChecked(false);
        }
    });
    port_diff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            port_na.setChecked(false);
            port_attempt.setChecked(false);
            port_diff.setChecked(b);
            port_easy.setChecked(false);
        }
    });
    port_easy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            port_na.setChecked(false);
            port_attempt.setChecked(false);
            port_diff.setChecked(false);
            port_easy.setChecked(b);
        }
    });
    port_attempt= (CheckBox)findViewById(R.id.portc_attempted_cb);
    port_diff= (CheckBox)findViewById(R.id.portc_difficult_cb);
    port_easy= (CheckBox)findViewById(R.id.portc_easy_cb);




Aucun commentaire:

Enregistrer un commentaire