PopupWindow 在调度事件上崩溃
我对 PopupWindow android 默认小部件有疑问。 当我触摸按钮显示弹出窗口并按手机上的后退按钮时,在显示弹出窗口之前,我有强制关闭消息,错误如下:
10-14 16:51:53.389: ERROR/AndroidRuntime(3766): FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.PopupWindow$PopupViewContainer.dispatchKeyEvent(PopupWindow.java:1342)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2471)
at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:2431)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
因此,经过我看到的一些测试,此错误在 android < 上重现。 2.3 版本(2.1、2.2) 我还深入研究了 grepcode 的源代码,有 method:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getRepeatCount() == 0) {
getKeyDispatcherState().startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP
&& getKeyDispatcherState().isTracking(event) && !event.isCanceled()) {
dismiss();
return true;
}
return super.dispatchKeyEvent(event);
} else {
return super.dispatchKeyEvent(event);
}
}
...
public KeyEvent.DispatcherState getKeyDispatcherState() {
return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null;
}
和方法 getKeyDispatcherState() return null
有谁解决了这个问题吗?
i have a trouble with PopupWindow android default widget.
When i touch button to show popup and than press back button on the phone, before popup was shown, i have force close message, the error is next:
10-14 16:51:53.389: ERROR/AndroidRuntime(3766): FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.PopupWindow$PopupViewContainer.dispatchKeyEvent(PopupWindow.java:1342)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2471)
at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:2431)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
So, after some tests i see, this bug is reproduces on android < 2.3 versions (2.1 , 2.2)
also i'm dig deep into the sources at grepcode, there is method:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getRepeatCount() == 0) {
getKeyDispatcherState().startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP
&& getKeyDispatcherState().isTracking(event) && !event.isCanceled()) {
dismiss();
return true;
}
return super.dispatchKeyEvent(event);
} else {
return super.dispatchKeyEvent(event);
}
}
...
public KeyEvent.DispatcherState getKeyDispatcherState() {
return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null;
}
and method getKeyDispatcherState() return null
Does anyone have solved this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题的焦点是你在 Popupwindow 显示之前将焦点放在了 Popupwindow 上,因此dispatchevent 会在你的 Activity 之前收到后退键,但现在你的 Popupwindow 没有显示。您可以通过不将焦点放在 Popupwindow 上进行测试,您就会明白我的意思。
The focus of this issue is you give focus to the Popupwindow before it is shown, so the dispatchevent will receive the back-key before your activity, but now your Popupwindow is not shown. You can test by not giving the focus to the Popupwindow and you will understand what I mean.
我相信这是 Android 上的一个错误。
发布在这里:
http://hg.mozilla.org/releases/mozilla-aurora/rev/caca38771162
This is a bug on android I believe.
Posted here:
http://hg.mozilla.org/releases/mozilla-aurora/rev/caca38771162