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
Where position is an int:
editText1.setSelection(position)
I won't get setSelection() method directly , so i done like below and work like charm
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);
Let editText2 is your second EditText view .then put following piece of code in onResume()
editText2.setFocusableInTouchMode(true);
editText2.requestFocus();
or put
<requestFocus />
in your xml layout of the second EditText view.
Remember call requestFocus()
before setSelection
for edittext.
In kotlin, you could create an extension function like this:
fun EditText.placeCursorAtLast() {
val string = this.text.toString()
this.setSelection(string.length)
}
and then simply call myEditText.placeCursorAtLast()