07-20-2023, 11:02 AM
If you called `setText` before and the new text didn't get layout phase call `setSelection` in a separate runnable fired by `View.post(Runnable)` (repost from [this][1] topic).
So, for me this code works:
editText.setText("text");
editText.post(new Runnable() {
@Override
public void run() {
editText.setSelection(editText.getText().length());
}
});
[1]:
Edit 05/16/2019: Right now I'm using Kotlin extension for that:
fun EditText.placeCursorToEnd() {
this.setSelection(this.text.length)
}
and then - editText.placeCursorToEnd().
So, for me this code works:
editText.setText("text");
editText.post(new Runnable() {
@Override
public void run() {
editText.setSelection(editText.getText().length());
}
});
[1]:
[To see links please register here]
Edit 05/16/2019: Right now I'm using Kotlin extension for that:
fun EditText.placeCursorToEnd() {
this.setSelection(this.text.length)
}
and then - editText.placeCursorToEnd().