使用" Enter]键。在softkeyboard,而不是点击按钮键 [英] Use "ENTER" key on softkeyboard instead of clicking button
本文介绍了使用" 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屋!
查看全文