Implementing Expandable Recycler View in Android Application

Updated 14 December 2016


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 ‘’

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 !




. . .

Leave a Comment

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


  • smwaura
    How do u implement search on this Expandable Recyclerview?
  • Shudy
    How can be implmented “onclickListener” on child , to get all the information and pass, to another activity?

    Thanks in advance

    • Shubham Agarwal
      You can add OnClickListener in the SubCategoryExpandableRecyclerAdapter. This is because we are binding the views using this adapter. If you want to provide listener on Child then you do this in onBindChildViewHolder() method.

      childViewHolder.txtListChild.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
      // your logic here

  • InstanttPS Xceleratics
    Kindly add notify datasetchanged too….
  • Shubham Agarwal
    First of all i don’t think that’s a navigation view. I think that’s a fragment rather than navigation view. But if you are planning to add expandable adapter in REcycler view check out this post or
    • Gaurav meghanathi
      i also created just simple recyclerview on fragment and i want to implement expnadable recyclerview like snapdeal and yahoo some navigation item to expand not each and every item to expand. and thanks to the help.
      • Shubham Agarwal
        Yes you can make a recycler view expandable. Just use a simple Recycler view with expandable recycler adapter provided by the adapter. Expandable recycler adapter allows you to set whether to expand the item or not. All depends on child items corresponding to parent item. If it is null, it will not update automatically.
  • sagar
    i m successfully add click listener to sub child. but how to expand those sub child, any idea, plz give some suggestion. thank you
    • Shubham Agarwal
      Child are automatically expanded if child item list is neither null and nor empty.
  • 4face
    Hello, where is my error?

    private List getGroups(){
    List reminderList = RealmReminders.getReminderList(mActivity, 0);
    List todayReminder = new ArrayList();
    List tomorrowReminder = new ArrayList();
    List otherDayReminder = new ArrayList();

    for (MyReminder thisReminder : reminderList){
    if (thisReminder.getRemindDay() == mThisDay) todayReminder.add(thisReminder);
    else if (thisReminder.getRemindDay() == mThisDay+1) tomorrowReminder.add(thisReminder);
    else if (thisReminder.getRemindDay() > mThisDay+1) otherDayReminder.add(thisReminder);

    List list = new ArrayList();
    ReminderGroup today, tomorrow, otherDay;
    if (todayReminder.size() != 0) {
    today = new ReminderGroup(“Today”, todayReminder);
    if (tomorrowReminder.size() != 0) {
    tomorrow = new ReminderGroup(“Tomorrow”, tomorrowReminder);
    if (otherDayReminder.size() != 0) {
    otherDay = new ReminderGroup(“Next”, otherDayReminder);
    return list;

    public void onBindParentViewHolder(MyParentViewHolder parentViewHolder, int position, ParentListItem parentListItem) {
    ReminderGroup reminderGroup = (ReminderGroup) parentListItem;;

    public void onBindChildViewHolder(MyChildViewHolder childViewHolder, int position, Object childListItem) {
    MyReminder reminder = (MyReminder) childListItem;

    java.lang.IllegalStateException: Null object added at com.bignerdranch.expandablerecyclerview.Adapter.ExpandableRecyclerAdapter.getItemViewType(

  • Start a Project

      Message Sent!

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

      Back to Home