How to replicate android:editable="false" in code?

In the layout you can set the EditText widget to be non-editable via the android:editable attribute.

How can I do this in code? I need to make the EditText widget to be editable depending on conditions.


editText.setFocusable(false);
editText.setClickable(false);

this ensure the EditText control can't be selected and focused, so it can't be edited.


I just tried this myself,

To disable editing text:

.setFocusable(false);

this also sets setFocusableInTouchMode to false!

To enable editing text:

setFocusableInTouchMode(true);

this also sets setFocusable to true;