I have a collapsible menu item that is defined in XML like this:
<item
android:id="@+id/searchMenu"
android:icon="@android:drawable/ic_menu_search"
android:showAsAction="withText|always|collapseActionView"
android:actionLayout="@layout/collapsible_edittext"/>
Here’s the collapsible_edittext.xml file:
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:inputType="text"
android:hint="@string/search"/>
When the item is expanded, and you change the orientation of the phone, it crashes giving this error in logcat:
07-24 08:59:19.353: E/AndroidRuntime(1284): Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.TextView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view’s id is id/searchMenu. Make sure other views do not use the same id.
If I remove the android:id=”@+id/searchMenu”, everything works fine but I need the item id in my code. This error only happens on ICS (It even works in the jelly bean emulator) and I’m using ActionBarSherlock 4.1.0
I finally found the problem, in fact it was not even linked with ActionBarSherlock (I removed action bar sherlock from my project and it was still crashing).
I only needed to add an id to my EditText and that’s it.