Answer the question
In order to leave comments, you need to log in
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;
}
});
Answer the question
In order to leave comments, you need to log in
remove the lisener from the EditText, just add it to the markup
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionNext"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question