Android – How to replicate android:editable=”false” in code

androidandroid-edittext

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.

Best Solution

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

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