关于Android PopupWindow中实用Spinner控件点击APP Crash情况整理!

场景异常信息如下:

android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@4190fd98 is not valid; is your activity running?

at android.view.ViewRootImpl.setView(ViewRootImpl.java:646)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:993)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:899)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:603)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:981)
at android.widget.Spinner.performClick(Spinner.java:609)
at android.view.View$PerformClick.run(View.java:17476)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5392)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)

at dalvik.system.NativeStart.main(Native Method)

解决办法:

方案一:

给Spinner控件加上android:spinnerMode="dialog"属性可以解决点击崩溃的问题,但是样式非常原始;

方案二:

未完待续....


关于Android PopupWindow中实用Spinner控件点击APP Crash情况整理!,布布扣,bubuko.com

关于Android PopupWindow中实用Spinner控件点击APP Crash情况整理!

上一篇:Java设计模式之观察者模式(Observer Pattern)


下一篇:安卓学习第8课——开关ToggleButton、Switch