Android的onKeyListener上的EditText只响应QUOT&[Enter]键;当pressed两次关键两次、关键、EditText、onKeyListener

2023-09-06 00:42:22 作者:琴音似君语

我有,我想给用户的pressing的Enter键响应一个EditText。下面是相关code:

I have an EditText that I want to respond to a user pressing the "Enter" key. Here is the relevant code:

EditText edittext = (EditText) findViewById(R.id.user_query);
edittext.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_CENTER)) {
            sendMessage(v);
            return true;
        }
        return false;
        }
    });

当我运行这在我的平板电脑(东芝茁壮成长),它完美的作品。然而,在我的手机(HTC Desire HD的),在OnKeyListener不火都当Enter键是pressed ......但工程Enter键是pressed第二次。这是为什么,我该如何解决?

When I run this on my tablet (Toshiba Thrive), it works perfectly. However, on my phone (HTC Desire HD), the OnKeyListener doesn't fire at all when the "Enter" key is pressed... but works when "Enter" is pressed a second time. Why is that, and how can I fix it?

推荐答案

通过自动更正在手机上,pressingEnter键一次选择单词的拼写建议。 pressing进入第二次发送键preSS的应用程序。这是一个功能,不是一个错误。

With autocorrect on the phone, pressing "Enter" once selects the suggested spelling of the word. Pressing "Enter" the second time sends the key press to the app. It's a feature, not a bug.