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.
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.
in your xml or
or
[Posting a new answer, since I can't comment on Josef's answer.]
The input filter works fine, but it has a subtle bug in it: typing over a selection will delete all the text.
For example, say you have the text
"foo"
in theEditText
. If you select it all (e.g., by double-clicking on it) and type'a'
, the text will disappear. This is because theInputFilter
will be called as:The proposed input filter will return the empty string in this case (because
src.length() < 1
isfalse
), which explains the missing text.The solution is to simply return
dst.subSequence(dstart, dend)
in the filter function. This will work fine even for deletions.