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"));
}

Inheritors

Functions

Link copied to clipboard
abstract fun isExpanded(): Boolean
Returns whether this widget is expanded.
Link copied to clipboard
abstract fun setExpanded(expanded: Boolean): Boolean
Sets the expanded state on this widget.