问题描述
我有一个微调的问题下拉列表,然后改变方向。
I have a problem with a spinner drop down list and changing orientations.
在我的活动,我显示一个对话框,在其中我有两个微调。当显示给用户的对话框,用户更改屏幕方向,一切都OK--在我的onPause,我只是简单地关闭对话框。
In my activity, I display a dialog in which I have two spinners. When the dialog is shown to the user and the user changes the screen orientation, everything is OK-- in my onPause, I just simply dismiss the dialog.
如果用户点击微调,一个下拉列表显示用户改变方向之前。但是,我遇到了一个错误,当用户不选择从下拉列表中任何东西,只留下改变方向之前展开的列表中。
If the user taps on the spinner, a drop-down list is shown to user before changing orientation. But I have encountered an error when the user doesn't select anything from the drop-down list, and just leaves the list expanded before changing orientation.
我已经尝试了很多事情来解决这个问题(即 spinner.setSelection(0)
在的onSaveInstanceState()
, 等等。)。我的想法是从code关闭下拉列表中,当用户不选择项目和方向发生变化。
I have tried many things to solve this problem (i.e. spinner.setSelection(0)
in onSaveInstanceState()
, etc.). My idea is to close the drop-down list from the code when the user doesn't select item and an orientation change occurs.
该错误是关于 Android.WindowLeaked
:
E/WindowManager( 2455): Activity pl.myapp.WebViewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45041e60 that was originally added here
E/WindowManager( 2455): android.view.WindowLeaked: Activity pl.myapp.WebViewActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@45041e60 that was originally added here
E/WindowManager( 2455): at android.view.ViewRoot.<init>(ViewRoot.java:247)
E/WindowManager( 2455): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager( 2455): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager( 2455): at android.view.Window$LocalWindowManager.addView(Window.java:424)
E/WindowManager( 2455): at android.app.Dialog.show(Dialog.java:241)
E/WindowManager( 2455): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
E/WindowManager( 2455): at android.widget.Spinner.performClick(Spinner.java:257)
E/WindowManager( 2455): at android.view.View$PerformClick.run(View.java:8816)
E/WindowManager( 2455): at android.os.Handler.handleCallback(Handler.java:587)
E/WindowManager( 2455): at android.os.Handler.dispatchMessage(Handler.java:92)
E/WindowManager( 2455): at android.os.Looper.loop(Looper.java:123)
E/WindowManager( 2455): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/WindowManager( 2455): at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager( 2455): at java.lang.reflect.Method.invoke(Method.java:521)
E/WindowManager( 2455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/WindowManager( 2455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/WindowManager( 2455): at dalvik.system.NativeStart.main(Native Method)
此外,出现此错误:
Also, this error appears:
D/AndroidRuntime( 2455): Shutting down VM
W/dalvikvm( 2455): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 2455): FATAL EXCEPTION: main
E/AndroidRuntime( 2455): java.lang.IllegalArgumentException: View not attached to window manager
E/AndroidRuntime( 2455): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
E/AndroidRuntime( 2455): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
E/AndroidRuntime( 2455): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
E/AndroidRuntime( 2455): at android.app.Dialog.dismissDialog(Dialog.java:278)
E/AndroidRuntime( 2455): at android.app.Dialog.access$000(Dialog.java:71)
E/AndroidRuntime( 2455): at android.app.Dialog$1.run(Dialog.java:111)
E/AndroidRuntime( 2455): at android.app.Dialog.dismiss(Dialog.java:268)
E/AndroidRuntime( 2455): at android.widget.Spinner.onDetachedFromWindow(Spinner.java:86)
E/AndroidRuntime( 2455): at android.view.View.dispatchDetachedFromWindow(View.java:6033)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1158)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 2455): at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1630)
E/AndroidRuntime( 2455): at android.view.ViewRoot.doDie(ViewRoot.java:2671)
E/AndroidRuntime( 2455): at android.view.ViewRoot.handleMessage(ViewRoot.java:1948)
E/AndroidRuntime( 2455): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2455): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2455): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 2455): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2455): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2455): at dalvik.system.NativeStart.main(Native Method)
修改
解决方法:
最后,我找到了原因这*放大器;#$%的误差。在表现在我的活动我有机器人:configChanges =方向,当我将其更改为安卓!configChanges =keyboardHidden |定位的问题消失了。
Finally I found what cause this *&#$% error. In manifest in my Activity I haveandroid:configChanges="orientation" , when I change it to android:configChanges="keyboardHidden|orientation" problem is gone !
THX 4帮助!
推荐答案
我有一个idea以prevent方向更改显示时微调对话框,却发现没有可靠的方法要做到这一点。我发现最好的解决办法是,replace微调器有一个按钮。
I had an idea to prevent orientation changes when dialog with spinner is displayed, but found that there is no reliable way to do that. The best solution that I found is to replace spinner with a button.
这篇关于微调下拉列表和屏幕方向变化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!