Below Code is Set cursor to Starting in EditText:
EditText editText = (EditText)findViewById(R.id.edittext_id);
editText.setSelection(0);
Below Code is Set cursor to end of the EditText:
EditText editText = (EditText)findViewById(R.id.edittext_id);
editText.setSelection(editText.getText().length());
Below Code is Set cursor after some 2th Character position :
EditText editText = (EditText)findViewById(R.id.edittext_id);
editText.setSelection(2);
Here we done this way to set cursor position to end of the text after
updating the text of EditText programmatically here, editText is EditText
Now cursor will be appear after"Updated New Text" String
EditText editText = (EditText)findViewById(R.id.edittext_id);
editText.setText("Updated New Text");
int position = editText.getText().length();
Editable editObj= editText.getText();
Selection.setSelection(editObj, position);
Thank you! Your method worked where many failed. You saved me a lot of head scratching and I am grateful.
ReplyDeleteThank You So Much
ReplyDelete