80,351
社区成员
发帖
与我相关
我的任务
分享
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (actionId == EditorInfo.IME_ACTION_SEARCH)
{
// 在这里做搜索操作
return true;
}
return false;
}
});
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
/**
* 因为部分机型的输入法,无法监听回车键,这里的例子是:小米2,系统4.1.1 JRO03L,输入法:搜狗输入法小米版V2.2。
* 无论怎么设置EditText控件的android:imeOptions,其actionId都为0,而且onEditorAction会被响应两次。
* 因此需要以下标记,来去掉第二次响应
*/
boolean b = true;
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (b)
{
b = false;
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED)
{
// TODO 在这里做你想要的操作
return true;
}
}
else
{
b = true;
}
return false;
}
});