How to Place the Cursor at the End of Text in EditText

How to Place the Cursor at the End of Text in EditText

22 May 2024 Stephan Petzl Leave a comment Tech-Help

When modifying the value of an EditText in Android, it is common to encounter an issue where the cursor moves to the beginning of the text. This article provides clear and practical solutions to ensure the cursor is placed at the end of the text in an EditText.

Solution in Kotlin

If you are working with Kotlin, the solution is straightforward. Use the setSelection() method to set the cursor to the end of the text.


Solution in Java

For those using Java, the approach is similar. Utilize the setSelection() method on your EditText instance.


Alternative Method: Using append()

Another effective method is to use the append() function, which appends the string value to the current EditText value and places the cursor at the end.


Handling Focus and Layout Phase

If you called setText() before and the new text didn’t get a layout phase, call setSelection() in a separate runnable fired by

editText.setText("text"); Runnable() {
    public void run() {

Custom Function for Kotlin

You can also create a Kotlin extension function to place the cursor at the end of the text.

fun EditText.placeCursorToEnd() {

Then, simply call:



These solutions should help you manage the cursor position in an EditText effectively. Whether you are using Kotlin or Java, the provided methods ensure the cursor is placed at the end of the text, enhancing the user experience.

Enhance Your Mobile Testing with Repeato

If you are a mobile developer looking to streamline your testing process, consider using Repeato. Repeato is a no-code test automation tool for iOS and Android, leveraging computer vision and AI to quickly create, run, and maintain automated tests. This tool allows developers to focus on creating a great product instead of spending time on testing, and it also empowers non-technical colleagues or QAs to manage the test automation process.

Like this article? there’s more where that came from!