How to set cursor to end of text in EditText in Kotlin?
Hello everyone! I've just started learning Android development in Kotlin and encountered what seems like a simple task, but I can't figure it out. \n\nI have a screen with an EditText input field. The user can edit the text, but at a certain point I need to programmatically set the cursor (caret) to the very end of this text. For example, after I load some text from a database or after the user clicks an "Add character" button.\n\nHere's my current code. I tried using `editText.setSelection(editText.text.length)`, but it doesn't work. The cursor either stays in place or disappears entirely. I also heard that I need to use some `KeyListener`, but I don't understand how that's related.\n\n```kotlin\n// Fragment of my code\nval editText: EditText = findViewById(
No answers yet.
Log in to leave an answer
Blogs