In Project Gradle
allprojects {
repositories {
..
..
maven { url 'https://jitpack.io' }
}
}
In app Gradle add
implementation 'com.github.kushalgupta0565:KExpandableRecyclerView:1.0.0'
Model for Group Item should extend Group
public class LocalGroup extends Group {
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Model for Child Item should extend Child
public class LocalChild extends Child {
String childData;
public LocalChild(String childData) {
this.childData = childData;
}
public String getChildData() {
return childData;
}
public void setChildData(String childData) {
this.childData = childData;
}
}
For Group items:
class ParentVH extends GroupViewHolder {
TextView textView;
public ParentVH(View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.textview);
}
}
For Child Items:
class ChildVH extends ChildViewHolder {
TextView textView;
public ChildVH(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.textview);
}
}
public class ExpandListAdapter extends ExpandableRecyclerViewAdapter<ParentVH, ChildVH>
implements ExpandableListItemClickListener {
...
...
...
...
}
public class MultipleViewTypeExpandListAdapter extends MultiViewTypeExpandaleAdapter<GroupViewHolder, ChildViewHolder>
implements ExpandableListItemClickListener {
...
...
...
...
}
RecyclerView recycler_view = findViewById(R.id.recycler_view);
List<ExpandableListItem> listData = new ArrayList<>();
..
..
..
..
ExpandListAdapter adapter = new ExpandListAdapter(listData);
recycler_view.setAdapter(adapter);