For details about how to use the Spinner control in the Android PopupWindow, click APP Crash !, Popupwindowspinner

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.