Select Checkbox and enable fields on Android

0

I'm using checkbox and an edittext. When the application starts, edittext is disabled. When the user checks the box for the checkbox, the edittext field enables.

I'm having trouble enabling. I already put it on OnCreate plus it does not recognize the click when I select the checkbox.

 private void escolhaCheckbox(){

    if (arvorismoInfantil.isChecked()){
        edt_arvorismoInfantil.setEnabled(true);
        int valorArvorismo = Integer.valueOf(edt_arvorismoInfantil.getText().toString());
        int total;
        total = valorArvorismo * 4;
        Log.i("total", String.valueOf(total));
    }
}

And in the method onCreate

 edt_arvorismoInfantil.setEnabled(false);
 escolhaCheckbox();
    
asked by anonymous 25.07.2017 / 16:29

1 answer

2

Use setOnCheckedChangeListener in your CheckBox . Here's how:

arvorismoInfantil.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // aqui você habilita seu edittext usando o isChecked
    }
});
    
25.07.2017 / 16:38