lundi 11 janvier 2016

Android Studio: Using CheckBox to set EditText enabled

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?




Aucun commentaire:

Enregistrer un commentaire