Android的onKeyListener上的EditText只响应QUOT&[Enter]键;当pressed两次关键 [英] Android onKeyListener on EditText only responds to "Enter" key when pressed twice

查看:94
本文介绍了Android的onKeyListener上的EditText只响应QUOT&[Enter]键;当pressed两次关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想给用户的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.

这篇关于Android的onKeyListener上的EditText只响应QUOT&[Enter]键;当pressed两次关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆