Set cursor position in android Edit text [duplicate]

不羁的心 提交于 2019-11-30 06:11:22
Hassaan Rabbani

You can achieve this by using :

Edittext.setSelection(Edittext.length());

this will put the cursor position in the end. otherwise you can get the text in a string and check the text position where you want to put the cursor and do it like this

String text = edittext.getText().toString();

for(int i = 0; i <text.length();i++)
{
//your logic here to check the position of text
}

and then

Edittext.setSelection(position);

Position at the start

editText.setSelection(0);

Position at the end

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

Position at the middle

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

Try this

editText1.requestFocus(Your_Text.length());

Hope it will help you.

editText1.setSelection(Your position)

or

EditText etext = (EditText)findViewById(R.id.inbox);
etext.setSelection(etext.getText().length());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!