I am changing the value of an EditText
on keyListener
.
But when I change the text the cursor is moving to the beginning of the EditText
.
I need the cursor to be at the end of the text.
How to move the cursor to the end of the text in a EditText
.
If you want to select all text and just entering new text instead of old one, you can use
editText.setSelection
is the magic here. Basically selection gives you place cursor at any position you want.This places cursor to end of EditText. Basically
editText.getText().length()
gives you text length. Then you usesetSelection
with length.editText.setSelection(0);
It is for setting cursor at start position (0).
The question is old and answered, but I think it may be useful to have this answer if you want to use the newly released DataBinding tools for Android, just set this in your XML :
User this CustomEditText in your XML file, this will work. I have tested this and it is working for me.