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
.
It work good for me!
Kotlin:
set the cursor to the starting position:
set the cursor to the end of the EditText:
Below Code is to place the cursor after the second character:
JAVA:
set the cursor to the starting position:
set the cursor to the end of the EditText:
Below Code is to place the cursor after the second character:
You should be able to achieve that with the EditText's method setSelection(), see here
If you called
setText
before and the new text didn't get layout phase callsetSelection
in a separate runnable fired byView.post(Runnable)
(repost from this topic).So, for me this code works:
You could also place the cursor at the end of the text in the
EditText
view like this:If your EditText is not clear: