Android Expandable RecyclerView Tutorial with Example

By | June 14, 2019
Expandable RecyclerView in Android Tutorial Example

Expandable RecyclerView in Android

Expandable recyclerView is a one of the most important feature in Android it is easily created our application using Expandable RecyclerView Library.

Expandable RecyclerView is a two contain view. parent view and child view. Parent is visible by default but the child view has to be expanded and collapsed. you can click on parent view to expand in recyclerView.

In this recyclerView is create two layout xml file is parent and child and then bind the adapter in different different view holder.you can create child holder and then create parent holder and this holder is bind the expandable recyclerView adapter.

Expandable recyclerView is provided two different different methods in bind holder.it is onCreateGroupViewHolder and then onCreateChildViewHolder methods are declared. onCreateGroupViewHolder is a bind on parent view and then onCreateChildViewHolder is bind on child view.

Now this recyclerView set the adapter and then run the application in your device to by default visibility parent view. you can click on parent view to expand this view and then open child view. you can another click on parent view to hide child view in recyclerView.

Example of Expandable RecyclerView in Android How to work Expandable RecyclerView ?

Implement Dependency in app level build.gradle File.

Create activity_main.xml File Follow this code.

Create item_parent.xml File Follow this code.

Create item_child.xml File Follow this code.

Create MainActivity.java File Follow this code.

Create ParentData.java File Follow this Code.

Create ChildData.java File Follow this Code.

Create ParentViewHolder.java File Follow this Code.

Create ChildViewHolders.java File Follow this Code.

Create MyAdapter.java File Follow this Code.

In this Example of Create Expandable recyclerView. in this recyclerView create two layout file parent and child. and then different different view holder in this layout file. i have create getter setter data in different different class in parent view and child view.and then create Expandable adapter class in implements library.

now this adapter to different different method override in parent and child view. in this two layout file bind in adapter and then set the list data and send the list in adapter. now you can click parent view to dispaly child view and i have put the arrow drawable to click listener to set and maintain drawable icon you can click collapse and expand.