Reputation: 197
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
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
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