Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set focus on the last character of EditText on Android

Tags:

java

android

I need to focus on the last character of EditText by coding way. I know that there is EditText.requestFocus, but it set focus on the first character. I'm using java.

like image 666
Sardor AKayumov Avatar asked Nov 26 '25 03:11

Sardor AKayumov


1 Answers

After the call to requestFocus(), you can set the position of the cursor at the end of the EditText as follows:

EditText editText = (EditText) findViewById(R.id.textId);
int pos = editText.getText().length();
editText.setSelection(pos);
like image 112
matdev Avatar answered Nov 27 '25 17:11

matdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!