Expandable Widget
interface ExpandableWidget
A widget that has expanded/collapsed state. When the expanded state changes, an event is dispatched so that other widgets may react via a .
Implementations of this interface should create an instance of ExpandableWidgetHelper and forward all calls to it.
The expanded state can saved across configuration changes by implementing onSaveInstanceState and onRestoreInstanceState:
@Override
protected Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
ExtendableSavedState state = new ExtendableSavedState(superState);
state.extendableStates.put(
"expandableWidgetHelper", expandableWidgetHelper.onSaveInstanceState());
return state;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (!(state instanceof ExtendableSavedState)) {
super.onRestoreInstanceState(state);
return;
}
ExtendableSavedState ess = (ExtendableSavedState) state;
super.onRestoreInstanceState(ess.getSuperState());
expandableWidgetHelper.onRestoreInstanceState(
ess.extendableStates.get("expandableWidgetHelper"));
}
Content copied to clipboard