Domanda

I have 6 checkboxs, only the first one will be clickable.. after the first one is checked, then allow the 2nd.. when the 2nd is checked, then allow the 3rd.. the checked checkboxs also need to be disabled to avoid the user uncheck them..

I think I need to use array? can't figure out how is the logic..

if(checkbox1.isChecked()){
            checkbox1.setEnabled(false);
        }else if(checkbox2.isChecked()){
            checkbox2.setEnabled(false);
        }

this won't work..

È stato utile?

Soluzione

You can set a listener for the checkboxes and enable the next one whenever the previous one is clicked.

Example:

CheckBox cb1 = (CheckBox) findViewById(R.id.checkbox1);
cb1.setOnCheckedChangeListener(new OnCheckedChangeListener(){

    @Override
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        if (isChecked){
            cb1.setEnabled(false);
            cb2.setEnabled(true);
        }
    }         
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top