Select Checkbox and enable fields on Android

Asked

Viewed 231 times

0

I am using checkbox and edittext. When the application starts, edittext is disabled. When the user marks the checkbox, the edittext field enables.

I’m having trouble enabling. I already put in Oncreate but 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();

1 answer

2

Use the setOnCheckedChangeListener in his CheckBox. Thus below:

arvorismoInfantil.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // aqui você habilita seu edittext usando o isChecked
    }
});
  • thank you very much, that’s right. It was right here in what I implemented .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.