I'm replacing some text in an EditText, then I want to move the cursor to the end of the current text input. It kind of seems to work - when I start typing again, the cursor seems to be at the end of the EditText, but it doesn't flash / blink anymore. I have to touch the EditText again for the cursor to start blinking again. Am I doing it wrong?:
editText.setSelection(editText.getText().length()-1);
Thanks
setSelection(editText. getText(). length()); This places cursor to end of EditText.
Say in your xml's edittext section, add android:paddingLeft="100dp" This will move your start position of cursor 100dp right from left end. Same way, you can use android:paddingRight="100dp" This will move your end position of cursor 100dp left from right end.
One trick I used was setting the text to "" and then appending the entire string I wanted.
i.e.
String newtext = editText.getText().toString() + "the new text"; editText.setText(""); editText.append(newtext);
This seems to place the cursor in the right place for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With