使用" Enter]键。在softkeyboard,而不是点击按钮键 [英] Use "ENTER" key on softkeyboard instead of clicking button

查看:172
本文介绍了使用" Enter]键。在softkeyboard,而不是点击按钮键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 我有一个搜索的EditText 和搜索按钮。当我键入​​搜索文本,我想使用输入上softkeyboard,而不是搜索按钮激活搜索功能。

Hello I've got a searched EditText and search Button. When I type the searched text, I'd like to use ENTER key on softkeyboard instead of search Button to activate search function.

感谢您的帮助提前。

推荐答案

您通过设置做一个 OnKeyListener 的EditText

下面是我自己的code的样本。我有一个的EditText addCourseText ,它会调用函数 addCourseFromTextBox 时,无论是回车键或方向键被点击。

Here is a sample from my own code. I have an EditText named addCourseText, which will call the function addCourseFromTextBox when either the enter key or the d-pad is clicked.

addCourseText = (EditText) findViewById(R.id.clEtAddCourse);
addCourseText.setOnKeyListener(new OnKeyListener()
{
    public boolean onKey(View v, int keyCode, KeyEvent event)
    {
        if (event.getAction() == KeyEvent.ACTION_DOWN)
        {
            switch (keyCode)
            {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    addCourseFromTextBox();
                    return true;
                default:
                    break;
            }
        }
        return false;
    }
});

这篇关于使用" Enter]键。在softkeyboard,而不是点击按钮键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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