Using this: How to make EditText not editable through XML in Android?
You said that you wanted your field to be editable after some logic. Do this:
KeyListener keyLis = textView.getKeyListener();
textView.setKeyListener(null);
Then, when you want your TextView
to be editable again, do this:
textView.setKeyListener(keyLis);
Documentation for TextView
class:
Two methods:
getKeyListener()
setKeyListener(KeyListener keyLis)
EDIT
I didn't find any beautiful answers, but I did find a few alternative ways to do this:
To make uneditable
valueText.setEnabled(false);
valueText.setClickable(false);
valueText.setFocusable(false);
And then,
valueText.setEnabled(true);
valueText.setClickable(true);
valueText.setFocusable(true);
You can also change what happens when the text is edited to make nothing happen: Can we have uneditable text in edittext
- There are some other very wild solutions, out there. They're not beautiful at all, though.
I recommend using the initial solution, unless somebody finds a quicker way.
Sorry I couldn't find a better way to do this :(