Place cursor at the end of text in EditText

2019-01-05 06:34发布

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.

23条回答
我命由我不由天
2楼-- · 2019-01-05 07:21

Try this:

EditText et = (EditText)findViewById(R.id.inbox);
et.setSelection(et.getText().length());
查看更多
男人必须洒脱
3楼-- · 2019-01-05 07:22

i think this can achieve what you want.

 Editable etext = mSubjectTextEditor.getText();
 Selection.setSelection(etext, etext.length());
查看更多
狗以群分
4楼-- · 2019-01-05 07:23

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"); 
查看更多
老娘就宠你
5楼-- · 2019-01-05 07:23

If you want to Place cursor at the end of text in EditText view

 EditText rename;
 String title = "title_goes_here";
 int counts = (int) title.length();
 rename.setSelection(counts);
 rename.setText(title);
查看更多
不美不萌又怎样
6楼-- · 2019-01-05 07:28
EditText editText=findViewById(R.id.et_id);

editText.requestFocus();
查看更多
We Are One
7楼-- · 2019-01-05 07:30

In my case I created the following kotlin ext. function, may be useful to someone

 private fun EditText.focus(){
        requestFocus()
        setSelection(length())
    }

Then use as follows

mEditText.focus()
查看更多
登录 后发表回答