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.

    1 answer 1

    According to en-SO, the transition to ENTER to the next EditText is decided by writing the next EditText in the markup attributes

     android:nextFocusRight="@+id/EDITTEXT2" 
    • one
      Doesn't work even if you remove all the listeners you hang? - Yuriy SPb
    • one
      If the problem is only with EditText with inputType = emailadress , then it might be worth trying NOT to call requestFocus on its next EditText ? - Yuriy SPb
    • one
      I decided) I added an input type - text, to fields that do not have a special type, and the transition occurs automatically without listeners - iamthevoid
    • one
      Those. The method presented by me works only if all EditText attributes have an inputType attribute? - Yuriy SPb
    • one
      Hmm ... Well, if it worked for you, then describe it in the answer - someday it will come in handy someday. - Yuriy SPb