onKey() method is not triggered as desired

Asked

Viewed 40 times

3

I’m trying to capture the enter key to jump from one EditText to another. The problem is that the method onKey() is not called when I press a key, for it to run I need to hold the key for a while.

My code:

 this.mHolder.editLargura.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER)
            {
                mHolder.editComprimento.requestFocus();
            }
            return false;
        }
    });

What can I do for him to be triggered without me having to hold a key?

  • The documentation of onKeyListener It says it’s only triggered for sure by physical keyboards. Software keyboards usually do not activate this Switch, except in some special cases. I don’t know what your case is, but you will probably need another type of Systener, like this one: https://developer.android.com/reference/android/inputmethodservice/KeyboardView.OnKeyboardActionListener.html

  • Thanks, that already helps

1 answer

1


  • Just to close, I managed to get enter to the next Edittext by adding this line in XML in the Edittext tag in question: android:inputType="textImeMultiline"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.