IllegalArgumentException: Wrong state class
For an Activity, I have two different layout files for portrait and landscape orientations. The elements of one orientation have direct relation to elements in the other orientation except that they may be related by base class but are not the exact same type and they do have the same id. So for instance:
layout/main_layout.xml:
...
<ListView
android:id="@+id/current_news_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
then in layout-land/main_layout.xml: CustomListView is a subclass of andr开发者_如何学JAVAoid.widget.AdapterView
...
<CustomListView
android:id="@+id/current_news_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
"IllegalArgumentException: Wrong state class" is thrown when changing orientations. Is this the expected behavior? I have not overridden configuration changing code and I'm letting the activity be completely destroyed and reconstructed. I've avoided other instances of having identical identifiers in the layout hierarchy at the same time.
Set the view's value saveEnabled to false.
http://developer.android.com/reference/android/view/View.html#attr_android:saveEnabled
While changing orientation, it tries to save the states of the views which have IDs, and tries to recreate the same while recreating your activity. So, for your case, one type cannot be converted into the other type. ie. A ListView can't be converted into a CustomListView.
And then, you will have to handle both the orientations yourself.
精彩评论