android SEND键崩溃
我需要检查回车键才能启动搜索例程。除了某些键盘之外,所有作品似乎都有一个“发送”按钮而不是“输入”按钮。当按下此键时,代码会转储。我下面有一个小样本。有什么想法吗?
tx1.setOnEditorActionListener (new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
System.out.println("Key: " + event.getKeyCode()); //BLOWS UP HERE
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// ...
}
}
}
}
I have a need to check for the enter key to start a search routine. All works except some keyboards seem to have a SEND button instead of the ENTER button. When this is pressed the code dumps. I have a small sample below. Any ideas?
tx1.setOnEditorActionListener (new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
System.out.println("Key: " + event.getKeyCode()); //BLOWS UP HERE
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// ...
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信在这种情况下该事件为空。为了检测软键盘上的发送操作,您的 onEditorActionListener 实际上应该这样做。
I believe that event is null in this case. for detecting the send action on the softkeyboard your onEditorActionListener should actually just do this.