davideas / FlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Apache License 2.0
3.55k stars 553 forks source link

Question about re-using expandable header items? #705

Closed johnernest02 closed 5 years ago

johnernest02 commented 5 years ago

Basically, is it possible?

I have a screen where 1st level items upon click will expand and show 2nd level items below it. The 2nd level items themselves look just like the 1st level items, only difference is a transparent indentation in the left. The 2nd level items themselves can also be clicked and show 3rd level items, which again looks like the 1st and 2nd level items with only another indentation in the left side. The hierarchy depends on the data returned from the database and the levels are not fixed. So I am looking for a solution where I can re-use the header items but I can't seem to wrap my head around how to implement it using the AbstractExpandableHeaderItem and AbsractExpandableItem. I have used this library before but only got until 2nd level items so I quite know the specifics of setting it up

johnernest02 commented 5 years ago

I am also using Kotlin by the way

davideas commented 5 years ago

@dev-JE02, the HeaderItem is mainly for sticky headers, if you don't need the sticky functionality you can use a normal ExpandableItem with subItems that in turn can be expanded as well for the 3rd level. You should use ExpansionLevel in the items definition, it should work.

johnernest02 commented 5 years ago

Okay but when adding to the adapter, am I supposed to use addItemToSection?

johnernest02 commented 5 years ago

Because I am finding it hard to put the 3rd level items and such inside the 2nd level sections as the 2nd level sections are normal ExpandableItems. Am I doing something wrong?

johnernest02 commented 5 years ago

I found that ExpandableItems has addSubItem method and subItems fields that I can use to add subItems. Thank you very much for the help

davideas commented 5 years ago

@dev-JE02, yes there are such methods for subItems, but pay attention that if you add them expanded (already visible), adapter must be called also with addItemToSection: Read Headers-and-Sections#following-the-use-case-2. Otherwise you don't need to call this method.