Fran Fitzpatrick Fran Fitzpatrick - 5 months ago 20
Android Question

How to make EditText not editable through XML in Android?

Can anyone tell me how to make an

EditText
not editable via XML? I tried setting
android:editable
to
false
, but


  1. it is deprecated; and

  2. it didn't work.


Answer

Use this simple code:

textView.setKeyListener(null);

It works.

Edit : To add KeyListener later, do following

1 : set key listener to tag of textView

textView.setTag(textView.getKeyListener());
textView.setKeyListener(null);

2 : get key listener from tag and set it back to textView

textView.setKeyListener((KeyListener) textView.getTag());