Enter key on EditText hitting onKey twice

前端 未结 7 1869
暖寄归人
暖寄归人 2021-01-07 18:25

I\'ve attached an OnKeyListener to an EditText. I\'ve overrode the onKey handler to capture a KeyEvent.

When a user hits the enter key (either their computer enter

相关标签:
7条回答
  • 2021-01-07 19:30

    Try this:

    mFilter.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_ENTER) {
                    // perform search
                    return true;
                }
            }
            return false;
        }
    });
    
    0 讨论(0)
提交回复
热议问题