Implementing Expandable Recycler View in Android Application

Updated 14 December 2016

Save

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.

Screenshot_20160429-223329

 

That’s all folks. Stay updated !

 

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

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


10 comments

  • smwaura
  • Shudy
    • Shubham Agarwal
  • InstanttPS Xceleratics
  • Shubham Agarwal
    • Gaurav meghanathi
      • Shubham Agarwal
  • sagar
    • Shubham Agarwal
  • 4face
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home