lightbulb_outline Please take our October 2018 developer survey. Start survey

ExpandableWidget

public interface ExpandableWidget

com.google.android.material.expandable.ExpandableWidget
Known Indirect Subclasses


A widget that has expanded/collapsed state. When the expanded state changes, an event is dispatched so that other widgets may react via a CoordinatorLayout.Behavior.

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 ERROR(/#onSaveInstanceState) and ERROR(/#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"));
 }
 

Summary

Public methods

abstract boolean isExpanded()

Returns whether this widget is expanded.

abstract boolean setExpanded(boolean expanded)

Sets the expanded state on this widget.

Public methods

isExpanded

boolean isExpanded ()

Returns whether this widget is expanded.

Implementations should call isExpanded().

Returns
boolean

setExpanded

boolean setExpanded (boolean expanded)

Sets the expanded state on this widget.

Implementations should call setExpanded(boolean).

Parameters
expanded boolean

Returns
boolean true if the expanded state changed as a result of this call.