I am changing the value of an EditText
on keyListener
.
But when I change the text the cursor is moving to the beginning of the EditText
.
I need the cursor to be at the end of the text.
How to move the cursor to the end of the text in a EditText
.
EditText editText = findViewById(R.id.editText); editText.setSelection(editText.getText().length()); // End point
CursorThis is another possible solution:
Just try this solution if it doesn't work for any reason:
This does the trick safely:
All the other codes I've tested didn't work good due to the fact that the user could still place the caret/cursor wherever in the middle of the string (ex.: 12|3.00 - where | is the cursor). My solution always puts the cursor in the end of the string whenever the touch occurs on the EditText.
The ultimate solution is:
@string/amount="0.00" @string/zero_value="0.00"
Hope it helps!
similar to @Anh Duy's answer, but it didnt work for me. i also needed the cursor to move to the end only when the user taps the edit text and still be able to select the position of the cursor afterwards, this is the only code that has worked for me
This works