我根据以下链接在我的对话框中制作了自定义弹出对话框。
我有按钮列表来显示弹出窗口。当我单击这些按钮时,将显示此对话框。我的问题有点奇怪。有时当我在对话框中选择注释编辑文本时,我得到了 WindowManager$BadTokenException。
06-06 12:34:57.878: E/AndroidRuntime(22951): FATAL EXCEPTION: main
06-06 12:34:57.878: E/AndroidRuntime(22951): android.view.WindowManager$BadTokenException: Unable to add window --
token android.view.ViewRootImpl$W@417d8d98 is not valid; is your activity running?
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.view.ViewRootImpl.setView(ViewRootImpl.java:585)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:326)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.view.Window$LocalWindowManager.addView(Window.java:547)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.PopupWindow.invokePopup(PopupWindow.java:988)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:845)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:809)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.Editor$PinnedPopupWindow.updatePosition(Editor.java:2147)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.Editor$PinnedPopupWindow.show(Editor.java:2104)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:2349)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.Editor.showSuggestions(Editor.java:1647)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.widget.Editor$1.run(Editor.java:1546)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.os.Handler.handleCallback(Handler.java:615)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.os.Handler.dispatchMessage(Handler.java:92)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.os.Looper.loop(Looper.java:137)
06-06 12:34:57.878: E/AndroidRuntime(22951): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-06 12:34:57.878: E/AndroidRuntime(22951): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 12:34:57.878: E/AndroidRuntime(22951): at java.lang.reflect.Method.invoke(Method.java:511)
06-06 12:34:57.878: E/AndroidRuntime(22951): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-06 12:34:57.878: E/AndroidRuntime(22951): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-06 12:34:57.878: E/AndroidRuntime(22951): at dalvik.system.NativeStart.main(Native Method)
我不知道为什么?我没有太多改变编码。我mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
在popupwindow
构造函数中添加了在键盘上方显示对话框。如果我在模拟器上运行,没有问题。在真实设备中,我得到了异常。有什么想法吗?
在按钮监听器中我这样实现
if(dialogNote == null) {
dialogNote = new QuickActionNote(AddNewNoteActivity.this);
}
dialogNote.show(btn);
谢谢。