0

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..

user2384424
  • 187
  • 1
  • 3
  • 13

2 Answers2

1

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

Nitish
  • 3,075
  • 3
  • 13
  • 28
  • Without using third party library need to implement this.. – user2384424 Sep 06 '21 at 08:07
  • You can refer to this article on how to create your own expandable recycler view [link](https://medium.com/codeshake/create-an-expandable-recyclerview-with-the-mergeadapter-254fd671fa5b) – Nitish Sep 06 '21 at 08:12
0

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

m.reiter
  • 1,796
  • 2
  • 11
  • 31