diff --git a/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java b/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java index bdc2c633..142886fb 100644 --- a/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java +++ b/library/src/se/emilsjolander/stickylistheaders/StickyListHeadersListView.java @@ -8,6 +8,7 @@ import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; +import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; import android.util.Log; @@ -1121,17 +1122,14 @@ public void setMultiChoiceModeListener(MultiChoiceModeListener listener) { @Override public Parcelable onSaveInstanceState() { - Parcelable superState = super.onSaveInstanceState(); - if (superState != BaseSavedState.EMPTY_STATE) { - throw new IllegalStateException("Handling non empty state of parent class is not implemented"); - } - return mList.onSaveInstanceState(); + return new SavedState(super.onSaveInstanceState(), mList.onSaveInstanceState()); } @Override public void onRestoreInstanceState(Parcelable state) { - super.onRestoreInstanceState(BaseSavedState.EMPTY_STATE); - mList.onRestoreInstanceState(state); + SavedState ss = (SavedState) state; + super.onRestoreInstanceState(ss.getSuperState()); + mList.onRestoreInstanceState(ss.wrappedState); } @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @@ -1155,4 +1153,41 @@ public void setStackFromBottom(boolean stackFromBottom) { public boolean isStackFromBottom() { return mList.isStackFromBottom(); } + + static class SavedState extends BaseSavedState { + private Parcelable wrappedState; + + /** + * Constructor called from {@link StickyListHeadersListView#onSaveInstanceState()} + */ + SavedState(Parcelable superState, Parcelable wrappedState) { + super(superState); + this.wrappedState = wrappedState; + } + + /** + * Constructor called from {@link #CREATOR} + */ + private SavedState(Parcel in) { + super(in); + wrappedState = in.readParcelable(null); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + super.writeToParcel(out, flags); + out.writeValue(wrappedState); + } + + public static final Parcelable.Creator CREATOR + = new Parcelable.Creator() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } }