【发布时间】:2013-08-13 21:14:41
【问题描述】:
我有一个EditView,我已经添加了:
android:imeActionLabel="Go"
这在键盘上显示“开始”按钮,但我不知道当用户单击“开始”按钮时如何执行操作。
有什么解决办法吗,如果有,我该怎么办?
【问题讨论】:
我有一个EditView,我已经添加了:
android:imeActionLabel="Go"
这在键盘上显示“开始”按钮,但我不知道当用户单击“开始”按钮时如何执行操作。
有什么解决办法吗,如果有,我该怎么办?
【问题讨论】:
EditText.OnEditorActionListener 是您正在寻找的,API 文档可以在here 找到。将为 GO 按钮调用的操作是 EditorInfo.IME_ACTION_GO。我在下面提供了一个简短的示例。
editText.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId==EditorInfo.IME_ACTION_GO)
{
//Handle go button pressed
}
return false;
}
});
【讨论】:
OnEditorActionListener() 显示此错误:类型 new TextView.OnEditorActionListener(){} 必须实现继承的抽象方法 TextView.OnEditorActionListener.onEditorAction(TextView, int, KeyEvent)