|  | 
|  | 1 | +# expandable-recyclerview | 
|  | 2 | +可以展开、折叠分组,支持添加多种divider的adapter | 
|  | 3 | + | 
|  | 4 | + | 
|  | 5 | +### 分组RecyclerView | 
|  | 6 | + | 
|  | 7 | +支持多种group布局和多种child布局 | 
|  | 8 | + | 
|  | 9 | +继承`NestedAdapter`,实现下列方法即可,跟使用`ExpandableListview`类似 | 
|  | 10 | + | 
|  | 11 | +```java | 
|  | 12 | + | 
|  | 13 | + protected abstract int getGroupCount(); | 
|  | 14 | + | 
|  | 15 | + protected abstract int getChildCount(int groupIndex); | 
|  | 16 | + | 
|  | 17 | + protected int getGroupItemViewType(int groupIndex) { | 
|  | 18 | + return 1; | 
|  | 19 | + } | 
|  | 20 | + | 
|  | 21 | + protected int getChildItemViewType(int groupIndex, int childIndex) { | 
|  | 22 | + return 1; | 
|  | 23 | + } | 
|  | 24 | + | 
|  | 25 | + protected abstract G onCreateGroupViewHolder(ViewGroup parent, int viewType); | 
|  | 26 | + | 
|  | 27 | + protected abstract void onBindGroupViewHolder(G holder, int groupIndex); | 
|  | 28 | + | 
|  | 29 | + protected abstract C onCreateChildViewHolder(ViewGroup parent, int viewType); | 
|  | 30 | + | 
|  | 31 | + protected abstract void onBindChildViewHolder(C holder, int groupIndex, int childIndex); | 
|  | 32 | + | 
|  | 33 | + | 
|  | 34 | +``` | 
|  | 35 | + | 
|  | 36 | + | 
|  | 37 | + | 
|  | 38 | +### 为NestedAdapter添加divider | 
|  | 39 | + | 
|  | 40 | +支持添加头部,尾部,group间,child间,group和child间添加自定义divider | 
|  | 41 | + | 
|  | 42 | +```java | 
|  | 43 | + | 
|  | 44 | + public NestedAdapterDivider setDividerBetweenGroup(Drawable dividerBetweenGroup)  | 
|  | 45 | + | 
|  | 46 | + public NestedAdapterDivider setDividerBetweenChild(Drawable dividerBetweenChild)  | 
|  | 47 | + | 
|  | 48 | + public NestedAdapterDivider setDividerBetweenGroupAndChild(Drawable dividerBetweenGroupAndChild)  | 
|  | 49 | + | 
|  | 50 | + public NestedAdapterDivider setDividerBeforeFirstGroup(Drawable dividerBeforeFirstGroup)  | 
|  | 51 | + | 
|  | 52 | + public NestedAdapterDivider setDividerAfterLastGroup(Drawable dividerAfterLastGroup)  | 
|  | 53 | + | 
|  | 54 | + | 
|  | 55 | +``` | 
|  | 56 | + | 
|  | 57 | +### 展开折叠Recyclerview | 
|  | 58 | + | 
|  | 59 | +继承自ExpandableAdapter即可,调用如下方法实现展开折叠,同样支持多种group布局和多种child布局 | 
|  | 60 | + | 
|  | 61 | +```java | 
|  | 62 | + | 
|  | 63 | + | 
|  | 64 | + public void collapseGroup(int groupIndex)  | 
|  | 65 | + | 
|  | 66 | + public void expandGroup(int groupIndex)  | 
|  | 67 | + | 
|  | 68 | + public boolean isExpand(int groupIndex)  | 
|  | 69 | + | 
|  | 70 | + public void collapseAllGroup()  | 
|  | 71 | + | 
|  | 72 | + | 
|  | 73 | +``` | 
|  | 74 | + | 
|  | 75 | + | 
|  | 76 | +### 支持局部刷新,局部移除添加 | 
|  | 77 | + | 
|  | 78 | +相关方法如下 | 
|  | 79 | + | 
|  | 80 | +```java | 
|  | 81 | + | 
|  | 82 | + public void notifyGroupItemChanged(int groupIndex)  | 
|  | 83 | + | 
|  | 84 | + public void notifyGroupChanged(int groupIndex)  | 
|  | 85 | + | 
|  | 86 | + public final void notifyChildItemChanged(int groupIndex, int childIndex)  | 
|  | 87 | + | 
|  | 88 | + public final void notifyChildItemRangeChanged(int groupIndex, int childIndex, int itemCount)  | 
|  | 89 | + | 
|  | 90 | + public final void notifyChildItemInserted(int groupIndex, int childIndex)  | 
|  | 91 | + | 
|  | 92 | + public final void notifyChildItemRangeInserted(int groupIndex, int childIndex, int itemCount)  | 
|  | 93 | + | 
|  | 94 | + public final void notifyChildItemRemoved(int groupIndex, int childIndex)  | 
|  | 95 | + | 
|  | 96 | + public final void notifyChildItemRangeRemoved(int groupIndex, int childIndex, int itemCount)  | 
|  | 97 | + | 
|  | 98 | +``` | 
0 commit comments