Java – Place cursor at the end of text in EditText

androidandroid-edittextjavakeylistenerkotlin

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.

Best Answer

Try this:

UPDATE:

Kotlin:

editText.setSelection(editText.length())//placing cursor at the end of the text

Java:

editText.setSelection(editText.getText().length());