Set cursor focus position in EditText

0

Is there any way when I call the virtual keyboard ( SoftKeyboard ) set the cursor position?

I have a EditText that already is filled by default the number 10 , when the keyboard starts I want the cursor to be just after 0 , but it is coming before 1 .

    
asked by anonymous 25.09.2017 / 19:03

1 answer

3

You can use EditText.setSelection . > + editText.getText().length()

Just run:

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

You can arrive when the field is in focus and fire setSelection at this time

editText.setOnFocusChangeListener(new OnFocusChangeListener()
{
    @Override
    public void onFocusChange(View view, boolean hasFocus)
    {
        if (hasFocus) {
            editText.setSelection(editText.getText().length());
        }
    }
});
    
25.09.2017 / 19:19