null keyevent and actionid = 0 in onEditorAction() (Jelly Bean / Nexus 7)(onEditorAction() 中的 null keyevent 和 actionid = 0 (Jelly Bean/Nexus 7))
问题描述
我有一个编辑文本,它在我的应用程序中用作搜索框.在我的 Nexus 7 上的 Jelly Bean 中,当我在我正在收听的文本框中输入一些内容并点击输入 KeyEvent = null 和 ActionId = 0 传递给 onEditorAction() 方法.有人遇到过这种情况么?我认为这可能是一个错误.
I have an edit text which functions as a search box in my application. In Jelly Bean on my Nexus 7 when I type something into the text box which I am listening on and hit enter the KeyEvent = null and ActionId = 0 passed into the onEditorAction() method. Has anyone else encountered this? I'm thinking it might be a bug.
在下面的第二个 if 语句中,我得到一个空指针,因为 actionId = 0 和 KeyEvent = null;
In the second if statement below I get a null pointer because the actionId = 0 and KeyEvent = null;
// Search field logic.
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.d(TAG, "onEditorAction");
if (event != null && event.getAction() != KeyEvent.ACTION_DOWN)
return false;
if (actionId == EditorInfo.IME_ACTION_SEARCH
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
.....Do some stuff();
}
}
推荐答案
最终添加了对 KeyEvent 的空检查.感谢 commonsware 指出这发生在 3.0+ 上.看起来更像是一种解决方法而不是解决方案,但它确实有效.
Ended up adding in a null check for KeyEvent. Thanks to commonsware for pointing out this happens on 3.0+. Seems more like a workaround then a solution, but it works.
// Search field logic.
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.d(TAG, "onEditorAction");
if (event != null && event.getAction() != KeyEvent.ACTION_DOWN) {
return false;
} else if (actionId == EditorInfo.IME_ACTION_SEARCH
|| event == null
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
.....Do some stuff();
}
}
这篇关于onEditorAction() 中的 null keyevent 和 actionid = 0 (Jelly Bean/Nexus 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:onEditorAction() 中的 null keyevent 和 actionid = 0 (Jelly
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01