public interface

ExpandableItemAdapter

com.h6ah4i.android.widget.advrecyclerview.expandable.ExpandableItemAdapter<GVH extends androidx.recyclerview.widget.RecyclerView.ViewHolder, CVH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
Known Indirect Subclasses

Summary

Public Methods
abstract int getChildCount(int groupPosition)
Gets the number of children in a specified group.
abstract long getChildId(int groupPosition, int childPosition)

Gets the ID for the given child within the given group.

abstract int getChildItemViewType(int groupPosition, int childPosition)
Gets the view type of the specified child.
abstract int getGroupCount()
Gets the number of groups.
abstract long getGroupId(int groupPosition)

Gets the ID for the group at the given position.

abstract int getGroupItemViewType(int groupPosition)
Gets the view type of the specified group.
abstract boolean getInitialGroupExpandedState(int groupPosition)
Gets initial expanded state of the group item.
abstract void onBindChildViewHolder(CVH holder, int groupPosition, int childPosition, int viewType, List<Object> payloads)
Called by RecyclerView to display the child data at the specified position.
abstract void onBindChildViewHolder(CVH holder, int groupPosition, int childPosition, int viewType)
Called by RecyclerView to display the child data at the specified position.
abstract void onBindGroupViewHolder(GVH holder, int groupPosition, int viewType)
Called by RecyclerView to display the group data at the specified position.
abstract void onBindGroupViewHolder(GVH holder, int groupPosition, int viewType, List<Object> payloads)
Called by RecyclerView to display the group data at the specified position.
abstract boolean onCheckCanExpandOrCollapseGroup(GVH holder, int groupPosition, int x, int y, boolean expand)

Called when a user attempt to expand/collapse a group item by tapping.

abstract CVH onCreateChildViewHolder(ViewGroup parent, int viewType)
Called when RecyclerView needs a new CVH of the given type to represent a child item.
abstract GVH onCreateGroupViewHolder(ViewGroup parent, int viewType)
Called when RecyclerView needs a new GVH of the given type to represent a group item.
abstract boolean onHookGroupCollapse(int groupPosition, boolean fromUser, Object payload)
Called when a group attempt to expand by user operation or by collapseGroup(int) method.
abstract boolean onHookGroupCollapse(int groupPosition, boolean fromUser)
Called when a group attempt to expand by user operation or by collapseGroup(int) method.
abstract boolean onHookGroupExpand(int groupPosition, boolean fromUser)
Called when a group attempt to expand by user operation or by expandGroup(int) method.
abstract boolean onHookGroupExpand(int groupPosition, boolean fromUser, Object payload)
Called when a group attempt to expand by user operation or by expandGroup(int) method.

Public Methods

public abstract int getChildCount (int groupPosition)

Gets the number of children in a specified group.

Parameters
groupPosition the position of the group for which the children count should be returned
Returns
  • the number of children

public abstract long getChildId (int groupPosition, int childPosition)

Gets the ID for the given child within the given group.

This ID must be unique across all children within the group. The combined ID (see getCombinedChildId(long, long)) must be unique across ALL items (groups and all children).

Parameters
groupPosition the position of the group that contains the child
childPosition the position of the child within the group for which the ID is wanted
Returns
  • the ID associated with the child

public abstract int getChildItemViewType (int groupPosition, int childPosition)

Gets the view type of the specified child.

Parameters
groupPosition the position of the group that contains the child
childPosition the position of the child within the group for which the view type is wanted
Returns
  • integer value identifying the type of the view needed to represent the group item at position. Type codes need positive number but not be contiguous.

public abstract int getGroupCount ()

Gets the number of groups.

Returns
  • the number of groups

public abstract long getGroupId (int groupPosition)

Gets the ID for the group at the given position. This group ID must be unique across groups.

The combined ID (see getCombinedGroupId(long)) must be unique across ALL items (groups and all children).

Parameters
groupPosition the position of the group for which the ID is wanted
Returns
  • the ID associated with the group

public abstract int getGroupItemViewType (int groupPosition)

Gets the view type of the specified group.

Parameters
groupPosition the position of the group for which the view type is wanted
Returns
  • integer value identifying the type of the view needed to represent the group item at position. Type codes need positive number but not be contiguous.

public abstract boolean getInitialGroupExpandedState (int groupPosition)

Gets initial expanded state of the group item. This method is called when initially creating a wrapper adapter and also when the data set is changed.

Parameters
groupPosition The position of the group
Returns
  • True for expanded, otherwise false.

public abstract void onBindChildViewHolder (CVH holder, int groupPosition, int childPosition, int viewType, List<Object> payloads)

Called by RecyclerView to display the child data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

Parameters
holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set
groupPosition The position of the group item within the adapter's data set
childPosition The position of the child item within the group
viewType The view type code
payloads A non-null list of merged payloads. Can be empty list if requires full update.

public abstract void onBindChildViewHolder (CVH holder, int groupPosition, int childPosition, int viewType)

Called by RecyclerView to display the child data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

Parameters
holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set
groupPosition The position of the group item within the adapter's data set
childPosition The position of the child item within the group
viewType The view type code

public abstract void onBindGroupViewHolder (GVH holder, int groupPosition, int viewType)

Called by RecyclerView to display the group data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

Parameters
holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set
groupPosition The position of the group item within the adapter's data set
viewType The view type code

public abstract void onBindGroupViewHolder (GVH holder, int groupPosition, int viewType, List<Object> payloads)

Called by RecyclerView to display the group data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

Parameters
holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set
groupPosition The position of the group item within the adapter's data set
viewType The view type code
payloads A non-null list of merged payloads. Can be empty list if requires full update.

public abstract boolean onCheckCanExpandOrCollapseGroup (GVH holder, int groupPosition, int x, int y, boolean expand)

Called when a user attempt to expand/collapse a group item by tapping.

Tips: If you want to set your own click event listener to group items, make this method always return false. It will disable auto expanding/collapsing when a group item is clicked.

Parameters
holder The ViewHolder which is associated to group item user is attempt to expand/collapse
groupPosition Group position
x Touched X position. Relative from the itemView's top-left
y Touched Y position. Relative from the itemView's top-left
expand true: expand, false: collapse
Returns
  • Whether to perform expand/collapse operation.

public abstract CVH onCreateChildViewHolder (ViewGroup parent, int viewType)

Called when RecyclerView needs a new CVH of the given type to represent a child item.

Parameters
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 View
Returns
  • A new child ViewHolder that holds a View of the given view type

public abstract GVH onCreateGroupViewHolder (ViewGroup parent, int viewType)

Called when RecyclerView needs a new GVH of the given type to represent a group item.

Parameters
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 View
Returns
  • A new group ViewHolder that holds a View of the given view type

public abstract boolean onHookGroupCollapse (int groupPosition, boolean fromUser, Object payload)

Called when a group attempt to expand by user operation or by collapseGroup(int) method.

Parameters
groupPosition The position of the group item within the adapter's data set
fromUser Whether the collapse request is issued by a user operation
payload Optional parameter, use null to identify a "full" update the group item
Returns
  • Whether the group can be collapsed. If returns false, the group keeps expanded.

public abstract boolean onHookGroupCollapse (int groupPosition, boolean fromUser)

Called when a group attempt to expand by user operation or by collapseGroup(int) method.

Parameters
groupPosition The position of the group item within the adapter's data set
fromUser Whether the collapse request is issued by a user operation
Returns
  • Whether the group can be collapsed. If returns false, the group keeps expanded.

public abstract boolean onHookGroupExpand (int groupPosition, boolean fromUser)

Called when a group attempt to expand by user operation or by expandGroup(int) method.

Parameters
groupPosition The position of the group item within the adapter's data set
fromUser Whether the expand request is issued by a user operation
Returns
  • Whether the group can be expanded. If returns false, the group keeps collapsed.

public abstract boolean onHookGroupExpand (int groupPosition, boolean fromUser, Object payload)

Called when a group attempt to expand by user operation or by expandGroup(int) method.

Parameters
groupPosition The position of the group item within the adapter's data set
fromUser Whether the expand request is issued by a user operation
payload Optional parameter, use null to identify a "full" update the group item
Returns
  • Whether the group can be expanded. If returns false, the group keeps collapsed.