I have EditText which displays something like ###-###. I want the user to be able to change this text only from the 1st position onward. That is user should not be able to touch a # in the middle and change it. How can I do this? Thanks a lot.
Sorry, I was not precise in my question. I want to disable even tapping in the middle of the text.
try creating a class the derives from edittext and override onSelectionChanged for example
Following code will force the curser to stay in last position if the user tries to move it with a tap on the edittext:
Note that the user can still change the position of the curser via arrow keys and / or trackball. As far as I know there is currently no workaround for this issue.
You need to implement the TextWatcher interface and override the three methods, afterTextChanged, beforeTextChanged, onTextChanged (you may only need to actually use one of them) Eg:
You then add this Watcher to your EditText, like so:
myEditText.addTextChangedListener(new MyTextWatcher());
Hope this helps.
This will "disable" tapping in the middle of your edit text