public abstract class ExpandableRecyclerAdapter<PVH extends ParentViewHolder,CVH extends ChildViewHolder> extends <any> implements ParentViewHolder.ParentListItemExpandCollapseListener
notifyParentItemInserted(int)
notifyParentItemRemoved(int)
notifyParentItemChanged(int)
notifyParentItemRangeInserted(int, int)
notifyChildItemInserted(int, int)
notifyChildItemRemoved(int, int)
notifyChildItemChanged(int, int)
methods and not the notify methods of RecyclerView.Adapter.| Modifier and Type | Class and Description |
|---|---|
static interface |
ExpandableRecyclerAdapter.ExpandCollapseListener
Allows objects to register themselves as expand/collapse listeners to be
notified of change events.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<java.lang.Object> |
mItemList
A
List of all currently expanded ParentListItem objects
and their children, in order. |
| Constructor and Description |
|---|
ExpandableRecyclerAdapter(java.util.List<? extends ParentListItem> parentItemList)
Primary constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
collapseAllParents()
Collapses all parents in the list.
|
void |
collapseParent(int parentIndex)
Collapses the parent with the specified index in the list of parents.
|
void |
collapseParent(ParentListItem parentListItem)
Collapses the parent associated with a specified
ParentListItem in
the list of parents. |
void |
collapseParentRange(int startParentIndex,
int parentCount)
Collapses all parents in a range of indices in the list of parents.
|
void |
expandAllParents()
Expands all parents in the list.
|
void |
expandParent(int parentIndex)
Expands the parent with the specified index in the list of parents.
|
void |
expandParent(ParentListItem parentListItem)
Expands the parent associated with a specified
ParentListItem in
the list of parents. |
void |
expandParentRange(int startParentIndex,
int parentCount)
Expands all parents in a range of indices in the list of parents.
|
int |
getItemCount()
Gets the number of parent and child objects currently expanded.
|
int |
getItemViewType(int position)
Gets the view type of the item at the given position.
|
protected java.lang.Object |
getListItem(int position)
Gets the list item held at the specified adapter position.
|
java.util.List<? extends ParentListItem> |
getParentItemList()
Gets the list of ParentItems that is backing this adapter.
|
void |
notifyChildItemChanged(int parentPosition,
int childPosition)
Notify any registered observers that the ParentListItem at
parentPosition has
a child located at childPosition that has changed. |
void |
notifyChildItemInserted(int parentPosition,
int childPosition)
Notify any registered observers that the ParentListItem reflected at
parentPosition
has a child list item that has been newly inserted at childPosition. |
void |
notifyChildItemMoved(int parentPosition,
int fromChildPosition,
int toChildPosition)
Notify any registered observers that the child list item contained within the ParentListItem
at
parentPosition has moved from fromChildPosition to toChildPosition. |
void |
notifyChildItemRangeChanged(int parentPosition,
int childPositionStart,
int itemCount)
Notify any registered observers that the ParentListItem at
parentPosition has
itemCount child Objects starting at childPositionStart that have changed. |
void |
notifyChildItemRangeInserted(int parentPosition,
int childPositionStart,
int itemCount)
Notify any registered observers that the ParentListItem reflected at
parentPosition
has itemCount child list items that have been newly inserted at childPositionStart. |
void |
notifyChildItemRangeRemoved(int parentPosition,
int childPositionStart,
int itemCount)
Notify any registered observers that the ParentListItem located at
parentPosition
has itemCount child list items that have been removed from the data set, previously
located at childPositionStart onwards. |
void |
notifyChildItemRemoved(int parentPosition,
int childPosition)
Notify any registered observers that the ParentListItem located at
parentPosition
has a child list item that has been removed from the data set, previously located at childPosition. |
void |
notifyParentItemChanged(int parentPosition)
Notify any registered observers that the ParentListItem at
parentPosition has changed. |
void |
notifyParentItemInserted(int parentPosition)
Notify any registered observers that the ParentListItem reflected at
parentPosition
has been newly inserted. |
void |
notifyParentItemMoved(int fromParentPosition,
int toParentPosition)
Notify any registered observers that the ParentListItem and it's child list items reflected at
fromParentPosition has been moved to toParentPosition. |
void |
notifyParentItemRangeChanged(int parentPositionStart,
int itemCount)
Notify any registered observers that the
itemCount ParentListItems starting
at parentPositionStart have changed. |
void |
notifyParentItemRangeInserted(int parentPositionStart,
int itemCount)
Notify any registered observers that the currently reflected
itemCount
ParentListItems starting at parentPositionStart have been newly inserted. |
void |
notifyParentItemRangeRemoved(int parentPositionStart,
int itemCount)
Notify any registered observers that the
itemCount ParentListItems previously located
at parentPositionStart have been removed from the data set. |
void |
notifyParentItemRemoved(int parentPosition)
Notify any registered observers that the ParentListItem previously located at
parentPosition
has been removed from the data set. |
void |
onAttachedToRecyclerView(RecyclerView recyclerView)
Implementation of Adapter#onAttachedToRecyclerView(RecyclerView).
|
abstract void |
onBindChildViewHolder(CVH childViewHolder,
int position,
java.lang.Object childListItem)
Callback called from onBindViewHolder(RecyclerView.ViewHolder, int)
when the list item bound to is a child.
|
abstract void |
onBindParentViewHolder(PVH parentViewHolder,
int position,
ParentListItem parentListItem)
Callback called from onBindViewHolder(RecyclerView.ViewHolder, int)
when the list item bound to is a parent.
|
void |
onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
Implementation of Adapter.onBindViewHolder(RecyclerView.ViewHolder, int)
that determines if the list item is a parent or a child and calls through
to the appropriate implementation of either
onBindParentViewHolder(ParentViewHolder, int, ParentListItem)
or onBindChildViewHolder(ChildViewHolder, int, Object). |
abstract CVH |
onCreateChildViewHolder(android.view.ViewGroup childViewGroup)
Callback called from
onCreateViewHolder(ViewGroup, int) when
the list item created is a child. |
abstract PVH |
onCreateParentViewHolder(android.view.ViewGroup parentViewGroup)
Callback called from
onCreateViewHolder(ViewGroup, int) when
the list item created is a parent. |
RecyclerView.ViewHolder |
onCreateViewHolder(android.view.ViewGroup viewGroup,
int viewType)
Implementation of Adapter.onCreateViewHolder(ViewGroup, int)
that determines if the list item is a parent or a child and calls through
to the appropriate implementation of either
onCreateParentViewHolder(ViewGroup)
or onCreateChildViewHolder(ViewGroup). |
void |
onDetachedFromRecyclerView(RecyclerView recyclerView)
Implementation of Adapter.onDetachedFromRecyclerView(RecyclerView)
|
void |
onParentListItemCollapsed(int position)
|
void |
onParentListItemExpanded(int position)
|
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 |
setExpandCollapseListener(ExpandableRecyclerAdapter.ExpandCollapseListener expandCollapseListener) |
protected java.util.List<java.lang.Object> mItemList
List of all currently expanded ParentListItem objects
and their children, in order. Changes to this list should be made through the add/remove methods
available in ExpandableRecyclerAdapterpublic ExpandableRecyclerAdapter(java.util.List<? extends ParentListItem> parentItemList)
mParentItemList and mItemList.
Changes to mParentItemList should be made through add/remove methods in
ExpandableRecyclerAdapterparentItemList - List of all ParentListItem objects to be
displayed in the RecyclerView that this
adapter is linked topublic RecyclerView.ViewHolder onCreateViewHolder(android.view.ViewGroup viewGroup,
int viewType)
onCreateParentViewHolder(ViewGroup)
or onCreateChildViewHolder(ViewGroup).viewGroup - 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.android.view.View of the given view type.public void onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
onBindParentViewHolder(ParentViewHolder, int, ParentListItem)
or onBindChildViewHolder(ChildViewHolder, int, Object).holder - The RecyclerView.ViewHolder to bind data toposition - The index in the list at which to bindjava.lang.IllegalStateException - if the item in the list is either null or
not of type ParentListItempublic abstract PVH onCreateParentViewHolder(android.view.ViewGroup parentViewGroup)
onCreateViewHolder(ViewGroup, int) when
the list item created is a parent.parentViewGroup - The ViewGroup in the list for which a PVH
is being createdPVH corresponding to the ParentListItem with
the ViewGroup parentViewGrouppublic abstract CVH onCreateChildViewHolder(android.view.ViewGroup childViewGroup)
onCreateViewHolder(ViewGroup, int) when
the list item created is a child.childViewGroup - The ViewGroup in the list for which a CVH
is being createdCVH corresponding to the child list item with the
ViewGroup childViewGrouppublic abstract void onBindParentViewHolder(PVH parentViewHolder, int position, ParentListItem parentListItem)
Bind data to the PVH here.
parentViewHolder - The PVH to bind data toposition - The index in the list at which to bindparentListItem - The ParentListItem which holds the data to
be bound to the PVHpublic abstract void onBindChildViewHolder(CVH childViewHolder, int position, java.lang.Object childListItem)
Bind data to the CVH here.
childViewHolder - The CVH to bind data toposition - The index in the list at which to bindchildListItem - The child list item which holds that data to be
bound to the CVHpublic int getItemCount()
mItemListpublic int getItemViewType(int position)
position - The index in the list to get the view type ofParentListItem and
for child list itemsjava.lang.IllegalStateException - if the item at the given position in the list is nullpublic java.util.List<? extends ParentListItem> getParentItemList()
notifyParentItemInserted(int)
notifyParentItemRemoved(int)
notifyParentItemChanged(int)
notifyParentItemRangeInserted(int, int)
notifyChildItemInserted(int, int)
notifyChildItemRemoved(int, int)
notifyChildItemChanged(int, int)
methods.public void onParentListItemExpanded(int position)
ParentViewHolder.ParentListItemExpandCollapseListener.onParentListItemExpanded(int).
Called when a ParentListItem is triggered to expand.
onParentListItemExpanded in interface ParentViewHolder.ParentListItemExpandCollapseListenerposition - The index of the item in the list being expandedpublic void onParentListItemCollapsed(int position)
ParentViewHolder.ParentListItemExpandCollapseListener.onParentListItemCollapsed(int).
Called when a ParentListItem is triggered to collapse.
onParentListItemCollapsed in interface ParentViewHolder.ParentListItemExpandCollapseListenerposition - The index of the item in the list being collapsedpublic void onAttachedToRecyclerView(RecyclerView recyclerView)
Called when this ExpandableRecyclerAdapter is attached to a RecyclerView.
recyclerView - The RecyclerView this ExpandableRecyclerAdapter
is being attached topublic void onDetachedFromRecyclerView(RecyclerView recyclerView)
Called when this ExpandableRecyclerAdapter is detached from a RecyclerView.
recyclerView - The RecyclerView this ExpandableRecyclerAdapter
is being detached frompublic void setExpandCollapseListener(ExpandableRecyclerAdapter.ExpandCollapseListener expandCollapseListener)
public void expandParent(int parentIndex)
parentIndex - The index of the parent to expandpublic void expandParent(ParentListItem parentListItem)
ParentListItem in
the list of parents.parentListItem - The ParentListItem of the parent to expandpublic void expandParentRange(int startParentIndex,
int parentCount)
startParentIndex - The index at which to to start expanding parentsparentCount - The number of parents to expandpublic void expandAllParents()
public void collapseParent(int parentIndex)
parentIndex - The index of the parent to collapsepublic void collapseParent(ParentListItem parentListItem)
ParentListItem in
the list of parents.parentListItem - The ParentListItem of the parent to collapsepublic void collapseParentRange(int startParentIndex,
int parentCount)
startParentIndex - The index at which to to start collapsing parentsparentCount - The number of parents to collapsepublic void collapseAllParents()
public void onSaveInstanceState(android.os.Bundle savedInstanceState)
Should be called from Activity.onSaveInstanceState(Bundle) in
the Activity that hosts the RecyclerView that this
ExpandableRecyclerAdapter 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
ExpandableRecyclerAdapter is attached to.
Assumes that the list of parent list items is the same as when the saved instance state was stored.
savedInstanceState - The Bundle from which the expanded
state map is loadedprotected java.lang.Object getListItem(int position)
position - The index of the list item to returnpublic void notifyParentItemInserted(int parentPosition)
parentPosition
has been newly inserted. The ParentListItem previously at parentPosition is now at
position parentPosition + 1.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the newly inserted ParentListItem in the data set, relative
to list of ParentListItems only.notifyParentItemRangeInserted(int, int)public void notifyParentItemRangeInserted(int parentPositionStart,
int itemCount)
itemCount
ParentListItems starting at parentPositionStart have been newly inserted.
The ParentListItems previously located at parentPositionStart and beyond
can now be found starting at position parentPositionStart + itemCount.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPositionStart - Position of the first ParentListItem that was inserted, relative
to list of ParentListItems only.itemCount - Number of items insertednotifyParentItemInserted(int)public void notifyParentItemRemoved(int parentPosition)
parentPosition
has been removed from the data set. The ParentListItems previously located at and after
parentPosition may now be found at oldPosition - 1.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the ParentListItem that has now been removed, relative
to list of ParentListItems only.public void notifyParentItemRangeRemoved(int parentPositionStart,
int itemCount)
itemCount ParentListItems previously located
at parentPositionStart have been removed from the data set. The ParentListItems
previously located at and after parentPositionStart + itemCount may now be found at
oldPosition - itemCount.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPositionStart - The previous position of the first ParentListItem that was
removed, relative to list of ParentListItems only.itemCount - Number of ParentListItems removed from the data setpublic void notifyParentItemChanged(int parentPosition)
parentPosition has changed.
This will also trigger an item changed for children of the ParentList specified.
This is an item change event, not a structural change event. It indicates that any
reflection of the data at parentPosition is out of date and should be updated.
The ParentListItem at parentPosition retains the same identity. This means
the number of children must stay the same.
parentPosition - Position of the item that has changedpublic void notifyParentItemRangeChanged(int parentPositionStart,
int itemCount)
itemCount ParentListItems starting
at parentPositionStart have changed. This will also trigger an item changed
for children of the ParentList specified.
This is an item change event, not a structural change event. It indicates that any reflection of the data in the given position range is out of date and should be updated. The ParentListItems in the given range retain the same identity. This means the number of children must stay the same.
parentPositionStart - Position of the item that has changeditemCount - Number of ParentListItems changed in the datasetpublic void notifyParentItemMoved(int fromParentPosition,
int toParentPosition)
fromParentPosition has been moved to toParentPosition.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
fromParentPosition - Previous position of the ParentListItem, relative to list of
ParentListItems only.toParentPosition - New position of the ParentListItem, relative to list of
ParentListItems only.public void notifyChildItemInserted(int parentPosition,
int childPosition)
parentPosition
has a child list item that has been newly inserted at childPosition.
The child list item previously at childPosition is now at
position childPosition + 1.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the ParentListItem which has been added a child, relative
to list of ParentListItems only.childPosition - Position of the child object that has been inserted, relative to children
of the ParentListItem specified by parentPosition only.public void notifyChildItemRangeInserted(int parentPosition,
int childPositionStart,
int itemCount)
parentPosition
has itemCount child list items that have been newly inserted at childPositionStart.
The child list item previously at childPositionStart and beyond are now at
position childPositionStart + itemCount.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the ParentListItem which has been added a child, relative
to list of ParentListItems only.childPositionStart - Position of the first child object that has been inserted,
relative to children of the ParentListItem specified by
parentPosition only.itemCount - number of children insertedpublic void notifyChildItemRemoved(int parentPosition,
int childPosition)
parentPosition
has a child list item that has been removed from the data set, previously located at childPosition.
The child list item previously located at and after childPosition may
now be found at childPosition - 1.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the ParentListItem which has a child removed from, relative
to list of ParentListItems only.childPosition - Position of the child object that has been removed, relative to children
of the ParentListItem specified by parentPosition only.public void notifyChildItemRangeRemoved(int parentPosition,
int childPositionStart,
int itemCount)
parentPosition
has itemCount child list items that have been removed from the data set, previously
located at childPositionStart onwards. The child list item previously located at and
after childPositionStart may now be found at childPositionStart - itemCount.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the ParentListItem which has a child removed from, relative
to list of ParentListItems only.childPositionStart - Position of the first child object that has been removed, relative
to children of the ParentListItem specified by
parentPosition only.itemCount - number of children removedpublic void notifyChildItemChanged(int parentPosition,
int childPosition)
parentPosition has
a child located at childPosition that has changed.
This is an item change event, not a structural change event. It indicates that any
reflection of the data at childPosition is out of date and should be updated.
The ParentListItem at childPosition retains the same identity.
parentPosition - Position of the ParentListItem who has a child that has changedchildPosition - Position of the child that has changedpublic void notifyChildItemRangeChanged(int parentPosition,
int childPositionStart,
int itemCount)
parentPosition has
itemCount child Objects starting at childPositionStart that have changed.
This is an item change event, not a structural change event. It indicates that any
The ParentListItem at childPositionStart retains the same identity.
reflection of the set of itemCount child objects starting at childPositionStart
are out of date and should be updated.
parentPosition - Position of the ParentListItem who has a child that has changedchildPositionStart - Position of the first child object that has changeditemCount - number of child objects changedpublic void notifyChildItemMoved(int parentPosition,
int fromChildPosition,
int toChildPosition)
parentPosition has moved from fromChildPosition to toChildPosition.
This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.
parentPosition - Position of the ParentListItem who has a child that has movedfromChildPosition - Previous position of the child list itemtoChildPosition - New position of the child list item