关于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情况整理!,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。