For details about how to use the Spinner control in the Android PopupWindow, click APP Crash !, Popupwindowspinner
The exception information is as follows:
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. Define mclick (Spinner. java: 609)
At android. view. View $ custom mclick. run (View. java: 17476)
At android. OS. Handler. handleCallback (Handler. java: 800)
At android. OS. Handler. dispatchMessage (Handler. java: 100)
At android. OS. lorule. loop (lorule. 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)
Solution:
Solution 1:
Adding the android: spinnerMode = "dialog" attribute to the Spinner control solves the click crash problem, but the style is very primitive;
Solution 2:
To be continued ....
Why can't I click another widget after the pop-up window of PopupWindow in android
Because PopupWindow gets the focus and others do not get the focus, you cannot click it. Set setFocusable to false.
How can I obtain the current focus of the main window in the popupwindow of android?
If PopupWindow is introduced into the main window in combination, there is no problem in accessing the controls in the main window.
If PopupWindow is a subclass, it is best to declare the subclass to the main window as a member class. In this way, the PopupWindow subclass can access external class controls.