3

我相信我的问题是我有一个纵向模式的画廊和一个横向模式的列表视图。他们都使用相同的适配器和相同的视图。但是,在方向更改时,列表视图会尝试从图库中读取信息并且程序崩溃。

画廊在恢复时可以很好地读取列表的信息。它是无法读取图库的保存状态的列表。我在下面附上了堆栈跟踪,尽管它告诉我的很少。您可以散发的任何光芒都会有所帮助!目标 api 是 3.0 顺便说一句。

07-22 20:58:35.660: ERROR/AndroidRuntime(2191): FATAL EXCEPTION: main
07-22 20:58:35.660: ERROR/AndroidRuntime(2191): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.awesome.OASAC/com.awesome.OASAC.OASACActivity}: java.lang.ClassCastException: android.widget.AbsSpinner$SavedState cannot be cast to android.widget.AbsListView$SavedState
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3096)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.access$1600(ActivityThread.java:123)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:997)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.os.Looper.loop(Looper.java:126)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.main(ActivityThread.java:3997)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at java.lang.reflect.Method.invokeNative(Native Method)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at java.lang.reflect.Method.invoke(Method.java:491)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at dalvik.system.NativeStart.main(Native Method)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191): Caused by: java.lang.ClassCastException: android.widget.AbsSpinner$SavedState cannot be cast to android.widget.AbsListView$SavedState
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.widget.AbsListView.onRestoreInstanceState(AbsListView.java:1520)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.View.dispatchRestoreInstanceState(View.java:8101)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:1972)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:766)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1958)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.view.View.restoreHierarchyState(View.java:8080)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.Fragment.restoreViewState(Fragment.java:516)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:742)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:921)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1579)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.Activity.performStart(Activity.java:4320)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1709)
07-22 20:58:35.660: ERROR/AndroidRuntime(2191):     ... 12 more
4

1 回答 1

3

据推测,您的 theGallery和name 都ListView相同。正如你所发现的,你不能安全地这样做。将其中一个名称更改为不同的名称。您还需要自己重写onSaveInstanceState()onRestoreInstanceState()转换两个实例状态(除了从每个方法链接到超类以继承默认行为)。

于 2011-07-22T23:48:24.920 回答