Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place cursor at the end of text in EditText

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.

like image 412
Manu Avatar asked Jun 02 '11 16:06

Manu


People also ask

How do I move my cursor to the end of EditText?

setSelection(editText. getText(). length()); This places cursor to end of EditText.

How do I change the cursor position in 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.

Can you set text in EditText?

In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.

How do you center text in EditText?

Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.


1 Answers

Try this:

UPDATE:

Kotlin:

editText.setSelection(editText.length())//placing cursor at the end of the text 

Java:

editText.setSelection(editText.getText().length()); 
like image 153
Marqs Avatar answered Sep 21 '22 19:09

Marqs