You can expand and fold groups and add multiple Divider adapters

The compile 'com. Wanjian: expandable - recyclerview: 0.0.1'

Grouping RecyclerView

Supports multiple group layouts and multiple child layouts

Inherit NestedAdapter and implement the following methods, similar to using ExpandableListview

    protected abstract int getGroupCount();

    protected abstract int getChildCount(int groupIndex);

    protected int getGroupItemViewType(int groupIndex) {
        return 1;
    }

    protected int getChildItemViewType(int groupIndex, int childIndex) {
        return 1;
    }

    protected abstract G onCreateGroupViewHolder(ViewGroup parent, int viewType);

    protected abstract void onBindGroupViewHolder(G holder, int groupIndex);

    protected abstract C onCreateChildViewHolder(ViewGroup parent, int viewType);

    protected abstract void onBindChildViewHolder(C holder, int groupIndex, int childIndex);

Copy the code

Add the Divider to the NestedAdapter

You can add a header, tail, and custom dividers between groups, children, groups, and children

public NestedAdapterDivider setDividerBetweenGroup(Drawable dividerBetweenGroup) public NestedAdapterDivider setDividerBetweenChild(Drawable dividerBetweenChild) public NestedAdapterDivider setDividerBetweenGroupAndChild(Drawable  dividerBetweenGroupAndChild) public NestedAdapterDivider setDividerBeforeFirstGroup(Drawable dividerBeforeFirstGroup) public NestedAdapterDivider setDividerAfterLastGroup(Drawable dividerAfterLastGroup)Copy the code

Expand fold Recyclerview

It can be extended from ExpandableAdapter, call the following method to expand and collapse, also support multiple group layout and multiple child layout

    public void collapseGroup(int groupIndex) 

    public void expandGroup(int groupIndex)  

    public boolean isExpand(int groupIndex) 
    
    public void collapseAllGroup()  
    
Copy the code

Support local refresh, local remove add

The relevant methods are as follows

    public void notifyGroupItemChanged(int groupIndex)  

    public void notifyGroupChanged(int groupIndex)  

    public final void notifyChildItemChanged(int groupIndex, int childIndex)  

    public final void notifyChildItemRangeChanged(int groupIndex, int childIndex, int itemCount)  

    public final void notifyChildItemInserted(int groupIndex, int childIndex)  
    
    public final void notifyChildItemRangeInserted(int groupIndex, int childIndex, int itemCount)  

    public final void notifyChildItemRemoved(int groupIndex, int childIndex)  

    public final void notifyChildItemRangeRemoved(int groupIndex, int childIndex, int itemCount) 
Copy the code