public abstract class ExpandableRecyclerViewAdapter<GVH extends GroupViewHolder,CVH extends ChildViewHolder> extends RecyclerView.Adapter implements ExpandCollapseListener, OnGroupClickListener
| Modifier and Type | Field and Description |
|---|---|
protected ExpandableList |
expandableList |
| Constructor and Description |
|---|
ExpandableRecyclerViewAdapter(java.util.List<? extends ExpandableGroup> groups) |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<? extends ExpandableGroup> |
getGroups()
The full list of
ExpandableGroup backing this RecyclerView |
int |
getItemCount() |
int |
getItemViewType(int position)
Gets the view type of the item at the given position.
|
boolean |
isGroupExpanded(ExpandableGroup group) |
boolean |
isGroupExpanded(int flatPos) |
abstract void |
onBindChildViewHolder(CVH holder,
int flatPosition,
ExpandableGroup group,
int childIndex)
Called from onBindViewHolder(RecyclerView.ViewHolder, int) when the list item
bound to is a child.
|
abstract void |
onBindGroupViewHolder(GVH holder,
int flatPosition,
ExpandableGroup group)
Called from onBindViewHolder(RecyclerView.ViewHolder, int) when the list item bound to is a
group
|
void |
onBindViewHolder(ViewHolder holder,
int position)
Implementation of Adapter.onBindViewHolder(RecyclerView.ViewHolder, int)
that determines if the list item is a group or a child and calls through
to the appropriate implementation of either
onBindGroupViewHolder(GroupViewHolder,
int,
ExpandableGroup)
or onBindChildViewHolder(ChildViewHolder, int, ExpandableGroup, int). |
abstract CVH |
onCreateChildViewHolder(android.view.ViewGroup parent,
int viewType)
Called from
onCreateViewHolder(ViewGroup, int) when the list item created is a child |
abstract GVH |
onCreateGroupViewHolder(android.view.ViewGroup parent,
int viewType)
Called from
onCreateViewHolder(ViewGroup, int) when the list item created is a group |
ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
Implementation of Adapter.onCreateViewHolder(ViewGroup, int)
that determines if the list item is a group or a child and calls through
to the appropriate implementation of either
onCreateGroupViewHolder(ViewGroup, int)
or onCreateChildViewHolder(ViewGroup, int)}. |
boolean |
onGroupClick(int flatPos)
Triggered by a click on a
GroupViewHolder |
void |
onGroupCollapsed(int positionStart,
int itemCount)
Called when a group is collapsed
|
void |
onGroupExpanded(int positionStart,
int itemCount)
Called when a group is expanded
|
void |
onRestoreInstanceState(android.os.Bundle savedInstanceState)
Fetches the expandable state map from the saved instance state
Bundle
and restores the expanded states of all of the list items. |
void |
onSaveInstanceState(android.os.Bundle savedInstanceState)
Stores the expanded state map across state loss.
|
void |
setOnGroupClickListener(OnGroupClickListener listener) |
void |
setOnGroupExpandCollapseListener(GroupExpandCollapseListener listener) |
boolean |
toggleGroup(ExpandableGroup group) |
boolean |
toggleGroup(int flatPos) |
protected ExpandableList expandableList
public ExpandableRecyclerViewAdapter(java.util.List<? extends ExpandableGroup> groups)
public ViewHolder onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
onCreateGroupViewHolder(ViewGroup, int)
or onCreateChildViewHolder(ViewGroup, int)}.parent - The ViewGroup into which the new View
will be added after it is bound to an adapter position.viewType - The view type of the new android.view.View.GroupViewHolder or a new ChildViewHolder
that holds a android.view.View of the given view type.public void onBindViewHolder(ViewHolder holder,
int position)
onBindGroupViewHolder(GroupViewHolder,
int,
ExpandableGroup)
or onBindChildViewHolder(ChildViewHolder, int, ExpandableGroup, int).holder - Either the GroupViewHolder or the ChildViewHolder to bind data toposition - The flat position (or index in the list of ExpandableList.getVisibleItemCount() in the list at which to bindpublic int getItemCount()
ExpandableList.getVisibleItemCount()public int getItemViewType(int position)
position - The flat position in the list to get the view type ofjava.lang.RuntimeException - if the item at the given position in the list is not foundpublic void onGroupExpanded(int positionStart,
int itemCount)
onGroupExpanded in interface ExpandCollapseListenerpositionStart - the flat position of the first child in the ExpandableGroupitemCount - the total number of children in the ExpandableGrouppublic void onGroupCollapsed(int positionStart,
int itemCount)
onGroupCollapsed in interface ExpandCollapseListenerpositionStart - the flat position of the first child in the ExpandableGroupitemCount - the total number of children in the ExpandableGrouppublic boolean onGroupClick(int flatPos)
GroupViewHolderonGroupClick in interface OnGroupClickListenerflatPos - the flat position of the GroupViewHolder that was clickedpublic boolean toggleGroup(int flatPos)
flatPos - The flat list position of the grouppublic boolean toggleGroup(ExpandableGroup group)
group - the ExpandableGroup being toggledpublic boolean isGroupExpanded(int flatPos)
flatPos - the flattened position of an item in the listgroup is expanded, false if it is collapsedpublic boolean isGroupExpanded(ExpandableGroup group)
group - the ExpandableGroup being checked for its collapsed stategroup is expanded, false if it is collapsedpublic void onSaveInstanceState(android.os.Bundle savedInstanceState)
Should be called from whatever Activity that hosts the RecyclerView that ExpandableRecyclerViewAdapter is attached to.
This will make sure to add the expanded state map as an extra to the
instance state bundle to be used in onRestoreInstanceState(Bundle).
savedInstanceState - The Bundle into which to store the
expanded state mappublic void onRestoreInstanceState(android.os.Bundle savedInstanceState)
Bundle
and restores the expanded states of all of the list items.
Should be called from Activity.onRestoreInstanceState(Bundle) in
the Activity that hosts the RecyclerView that this
ExpandableRecyclerViewAdapter is attached to.
savedInstanceState - The Bundle from which the expanded
state map is loadedpublic void setOnGroupClickListener(OnGroupClickListener listener)
public void setOnGroupExpandCollapseListener(GroupExpandCollapseListener listener)
public java.util.List<? extends ExpandableGroup> getGroups()
ExpandableGroup backing this RecyclerViewExpandableGroup that this object was instantiated withpublic abstract GVH onCreateGroupViewHolder(android.view.ViewGroup parent, int viewType)
onCreateViewHolder(ViewGroup, int) when the list item created is a groupviewType - an int returned by getItemViewType(int)parent - the ViewGroup in the list for which a GVH is being createdGVH corresponding to the group list item with the ViewGroup parentpublic abstract CVH onCreateChildViewHolder(android.view.ViewGroup parent, int viewType)
onCreateViewHolder(ViewGroup, int) when the list item created is a childviewType - an int returned by getItemViewType(int)parent - the ViewGroup in the list for which a CVH is being createdCVH corresponding to child list item with the ViewGroup parentpublic abstract void onBindChildViewHolder(CVH holder, int flatPosition, ExpandableGroup group, int childIndex)
Bind data to the CVH here.
holder - The CVH to bind data toflatPosition - the flat position (raw index) in the list at which to bind the childgroup - The ExpandableGroup that the the child list item belongs tochildIndex - the index of this child within it's ExpandableGrouppublic abstract void onBindGroupViewHolder(GVH holder, int flatPosition, ExpandableGroup group)
Bind data to the GVH here.
holder - The GVH to bind data toflatPosition - the flat position (raw index) in the list at which to bind the groupgroup - The ExpandableGroup to be used to bind data to this GVH