user2384424
user2384424

Reputation: 197

How to get expandable items in recyclerview?

I want to display recyclerview with sub items which needs to expand/collapse.

For example,

Main Item 1 (expand)

--- Child Item 1 (expand) ------- sub Item 1 ------- sub Item 2

--- Child Item 2 (expand) ------- sub Item 1

Main Item 2 (expand)

--- Child Item 1 (expand) ------- sub Item 1 ------- sub Item 2

--- Child Item 2 --- Child Item 3

Main Item 3 Main Item 4

When I click on mainitem it needs to show child items and when I click on child item 1 it needs to expand and display sub items.

How to do this in Android recyclerview..

Upvotes: 0

Views: 1125

Answers (2)

m.reiter
m.reiter

Reputation: 2565

ExpandableListView is the best option i can think of right now.

Please note, that it's NOT based on RecyclerView, but on ListView, but that should only matter if you have tons of items

Upvotes: 0

Nitish
Nitish

Reputation: 3411

Instead of recyclerview , you can use expandable recyclerview

compile 'com.thoughtbot:expandablerecyclerview:1.4'

For more info you can refer to :
https://github.com/thoughtbot/expandable-recycler-view

Edit:
To create your own custom expandable recycler view, you can use ConcatAdapter to achive this. Refer to this article for more details:
https://medium.com/codeshake/create-an-expandable-recyclerview-with-the-mergeadapter-254fd671fa5b

Upvotes: 1

Related Questions