0

AbsListView在几个片段和活动中使用 a,以便我可以ListView在纵向模式和GridView横向模式下使用 a。我在 ICS 和 JB 中进行了所有日常测试,而且效果很好。我开始在 GB 设备 (2.3.6) 上进行测试,当我在其中一个屏幕处于活动状态的情况下旋转设备时收到 ClassCastException。这是堆栈跟踪:

05-09 14:04:55.019: E/AndroidRuntime(6052): Caused by: java.lang.ClassCastException: android.widget.ListView$SavedState
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.widget.AbsListView.onRestoreInstanceState(AbsListView.java:1018)
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.view.View.dispatchRestoreInstanceState(View.java:6325)
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:1314)
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:767)
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1301)
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.view.View.restoreHierarchyState(View.java:6304)
05-09 14:04:55.019: E/AndroidRuntime(6052):     at android.support.v4.app.Fragment.restoreViewState(Fragment.java:417)
4

1 回答 1

1

由于此视图根据方向具有不同的类型,因此不需要保存状态。通过禁用它将从/事件setSaveEnabled中删除此控件。onSaveInstanceStateonRestoreInstanceState

    list = (AbsListView) findViewById(R.id.list);
    list.setSaveEnabled(false);
于 2013-05-09T21:29:58.517 回答