Kotlin Move Cursor to End of Text (KMCET)

"I changed some text in an EditText, then I wanted to move the cursor to the end of the current text input. This seemed to work - when I started typing again, the cursor seemed to be at the end of the EditText, but it wasn't blinking anymore. I had to touch the EditText again for the cursor to start blinking again. Am I doing something wrong?"

Actually, the method below is quite correct, but it may not suit my needs.

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

Finally, with a little tricky way, I made it perfect for the case I was facing, here's how.
String newtext = editText.getText().toString() + "the new text" ;
editText.setText( "" );
editText.append(newtext);

One trick I use is to set the text to "" and then append the entire string I want.

Post a Comment

Previous Next

نموذج الاتصال