EditText/TextWatcher brings me back to the beginning of the input line

35 views Asked by At
public void afterTextChanged(Editable s) {
    if (editText.getText().length() == 12) {
        editText.setText(editText.getText().subSequence(0, editText.getText().length() - 1));
    }

    //problem in this part of code
    if (editText.getText().length() == 2 || editText.getText().length() == 5 || editText.getText().length() == 8) {
        editText.setText(editText.getText()+"/");
    }
}    

How can I go back to the end of the input line?

1

There are 1 answers

0
fchristysen On BEST ANSWER

You could add this at the end of your method:

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

PS: Would be better if you describe more about your problem, so it would be easier to understand. :)