R
R
Ryabos2019-08-26 08:25:51
Android
Ryabos, 2019-08-26 08:25:51

How to navigate to another EditText when pressing enter on one EditText?

I'm making a form for which filling speed is critical. I decided to do this: enter text in EditTextA, press enter, and you can immediately enter text in EditTextB, without clicking on it. But when you click on enter, the keyboard doesn't appear, although the cursor moves from EditTextA to EditTextB.

fieldA.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN &&
                        keyCode == KeyEvent.KEYCODE_ENTER) {
                    Object service = getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (service != null) {
                        ((InputMethodManager) service).hideSoftInputFromWindow(fieldA.getWindowToken(), 0);
                        fieldB.requestFocus();
                        ((InputMethodManager) service).showSoftInput(fieldB, InputMethodManager.SHOW_IMPLICIT);
                    }
                    return true;
                }
                return false;
            }
        });

I tried various combinations of three lines inside the if block, the result is the same.
Maybe it's the android:imeOptions parameter for EditTextA?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
terminator-light, 2019-08-26
@Ryabos

remove the lisener from the EditText, just add it to the markup

android:maxLines="1"
android:inputType="text"
android:imeOptions="actionNext"

How to move focus through EditText on Android

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question