There is a markup page registration. One after another are the fields First Name, Last Name, Email, Password, Phone. the last three have a corresponding inputType. There is no more difference between them. It is necessary to implement the transition to the next field by Enter.
Since the last ones guarantee the transition to the next field by enter, I don’t touch them, on the first 2 EditText I attach such a TextWatcher
private TextWatcher focusNext(final EditText current, final EditText next) { return new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { int index = s.length() - 1; if (index >= 0) { char c = s.charAt(index); if (c == '\n' || c == '\r') { current.setText(current.getText().toString().replaceAll(System.getProperty("line.separator"), "")); next.requestFocus(); } } } }; } The result is the following - I get up on the "NAME" - enter translates into "last name", regardless of whether something was entered in the field or not. Line separator is validly deleted. I do the same action on the names, Line.separator is removed, but the focus does not just go to the Email, but then goes to the password.
How can this problem be solved? And the transition to the next et by enter and input are needed, can TextWatcher implement it in another way?
Tried to add onKeyListener, but the result is about the same. By pressing the Enter KeyCode, both EditText are immediately caught, for which onKeyListener is set and the focus is moved to Email, regardless of whether the name or surname is Enter
I decided to add input type to ET, without a specialized type and remove the listeners.