Start a Project

Implementing Expandable Recycler View in Android Application

Expandable Recycler view is alternative of ExpandableListView. There are many times when ExapandableListView don’t perform as per the requirement. It fails in the coordinator layout as well as have layout height issue.

Thus we are creating a simple Expandable Recycle view using bignerdranch’s expandablerecyclerview library.

Dependency used in this blog:

 compile ‘com.bignerdranch.android:expandablerecyclerview:2.1.1’

1. Custom Parent and Child Classed used to represent the relationship

SubcategoryParentListItem is our parent class that is used to store the data relevant to parent.

SubcategoryChildListItem is our simple child class used to display the content in each child of parent

 

 

2. Preparing data for Expandable Recycler View

Creating List of parent item to be displayed in a view.

 

Creating a list of child item and setting this list to a particular parent.

subcategoryParentListItem.setChildItemList(childItemList); // set the list of child item for a parent item.

3. Setting adapter to a Recycler View to make it EXPANDABLE

4. Implementing Custom adapter to support expansion of views.

Unlike traditional Recycler view in which we have a single view holder and thus single onCreateViewHolder and onBindViewHolder,
We have two different sets of onCreateViewHolder and onBindViewHolder.

 

That’s all folks. Stay updated !

 

REFERENCE:
https://github.com/bignerdranch/expandable-recycler-view

 

Exit mobile version