Meline Meline - 2 months ago 7
Android Question

Enable Edittext after disabling it

OnButtonClick listener I want to disable the EditText to edit, and then turn it on again.

With below two lines I disabled EditText

editTextWight.setEnabled(false);
editTextWight.setFocusable(false);


But when I then try to turn it to edit all else fails. The keyboard does not open.

editTextWight.setFocusable(true);
editTextWight.setFocusableInTouchMode(true);
editTextWight.setClickable(true);
editTextWight.setEnabled(true);


Please help me to enable the EditText.

Answer

to disable edit text use

editTextWight.setEnabled(false);
editTextWight.setInputType(InputType.TYPE_NULL);
editTextWight.setFocusable(false);

to enable edit text use

editTextWight.setEnabled(true);
editTextWight.setInputType(InputType.TYPE_CLASS_TEXT);
editTextWight.setFocusable(true);