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 android.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With