Skip to content

Instantly share code, notes, and snippets.

@dmersiyanov
Created July 12, 2022 10:47
Show Gist options
  • Save dmersiyanov/d057f02f825457a25caa3631bd137265 to your computer and use it in GitHub Desktop.
Save dmersiyanov/d057f02f825457a25caa3631bd137265 to your computer and use it in GitHub Desktop.
Save state for android custom view
internal class SavedState : BaseSavedState {
var isExpanded: Boolean = false
constructor(superState: Parcelable) : super(superState)
constructor(source: Parcel) : super(source) {
isExpanded = source.readBoolean()
}
constructor(source: Parcel?, loader: ClassLoader?) : super(source, loader)
override fun writeToParcel(out: Parcel, flags: Int) {
super.writeToParcel(out, flags)
out.writeBoolean(isExpanded)
}
companion object {
@JvmField
val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> {
override fun createFromParcel(source: Parcel) = SavedState(source)
override fun newArray(size: Int): Array<SavedState> = newArray(size)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment