2

In android studio, I am attempting to use a CheckBox to control whether a numerical EditText is enabled or disabled. The relevant code when the checkbox is clicked:

    boolean checked = ((CheckBox) view).isChecked();
    EditText yzEdit = (EditText) findViewById(R.id.yzEdit);

    // Check which checkbox was clicked
    switch(view.getId()) {
        case R.id.yzCheck:
            if (checked){
                yzEdit.setBackgroundColor(Color.parseColor("#FFFFFF"));
                yzEdit.setTextIsSelectable(true);
                yzEdit.setFocusable(true);
                yzEdit.setFocusableInTouchMode(true);
                yzEdit.setCursorVisible(true);
                yzEdit.setEnabled(true);
            }
            else{
                yzEdit.setBackgroundColor(Color.parseColor("#CCCCCC"));
                yzEdit.setTextIsSelectable(false);
                yzEdit.setFocusable(false);
                yzEdit.setFocusableInTouchMode(false);
                yzEdit.setCursorVisible(false);
                yzEdit.setEnabled(false);
            }
            break;
    }

Everything almost works. However, when I check the box, enabling yzEdit, then click on yzEdit, no user numerical keyboard pops up directly. So the user cannot enter any numbers into the newly enabled EditText (except in a roundout way of focusing on it through "Next" from a previous EditText.

Which property am I looking for that controls this behavior?

HoosierPhysics
  • 133
  • 1
  • 8

1 Answers1

1

You need to use a listener on your checkbox, if you want to detect if an object has changed his state.

For your case, it's setOnCheckedChangeListener() to use on your checkbox.

You can take a look here : http://developer.android.com/reference/android/widget/CompoundButton.html and : Android: checkbox listener

Community
  • 1
  • 1
ths83
  • 11
  • 1