Place cursor at the end of text in EditText Place cursor at the end of text in EditText android android

Place cursor at the end of text in EditText


Try this:

UPDATE:

Kotlin:

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

Java:

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


There is a function called append for ediitext which appends the string value to current edittext value and places the cursor at the end of the value.You can have the string value as the current ediitext value itself and call append();

myedittext.append("current_this_edittext_string"); 


Kotlin:

set the cursor to the starting position:

val editText = findViewById(R.id.edittext_id) as EditTexteditText.setSelection(0)

set the cursor to the end of the EditText:

val editText = findViewById(R.id.edittext_id) as EditTexteditText.setSelection(editText.text.length)

Below Code is to place the cursor after the second character:

val editText = findViewById(R.id.edittext_id) as EditTexteditText.setSelection(2)

JAVA:

set the cursor to the starting position:

 EditText editText = (EditText)findViewById(R.id.edittext_id); editText.setSelection(0);

set the cursor to the end of the EditText:

EditText editText = (EditText)findViewById(R.id.edittext_id);editText.setSelection(editText.getText().length());

Below Code is to place the cursor after the second character:

EditText editText = (EditText)findViewById(R.id.edittext_id);editText.setSelection(2);