How to set cursor position in EditText?

2019-01-07 04:54发布

There are two EditText,while loading the page a text is set in the first EditText, So now cursor will be in the starting place of EditText, I want to set cursor position in the second EditText which contains no data. How to do this?

20条回答
我只想做你的唯一
2楼-- · 2019-01-07 05:32

some time edit text cursor donot comes at particular position is if we directly use editText.setSelection(position); . In that case you can try

editText.post(new Runnable() {
                @Override
                public void run() {
                    editText.setSelection(string.length());
                }
            });
查看更多
姐就是有狂的资本
3楼-- · 2019-01-07 05:36

If you want to set cursor position in EditText? try these below code

EditText rename;
 String title = "title_goes_here";
 int counts = (int) title.length();
 rename.setSelection(counts);
 rename.setText(title);
查看更多
登录 后发表回答