1

is it possible to make an expandable list within an expandable list

i am making a recipe application and i've three expandable lists of the same type - vitamins, minerals and macro-nutrients created with expandablelistview with android studio

is it possible to put these three expandable lists under an expandable list called nutrition and if so could you briefly outline how please. thanks in advance

john
  • 31
  • 1
  • 2
  • 6
  • 1
    I suggest you use 3-level expandablelistview instead. Pls see my answer at the following http://stackoverflow.com/questions/32880281/how-to-add-three-level-listview-in-expandablelistview-in-android/ and http://stackoverflow.com/questions/32713909/after-maintaining-collapse-expand-state-for-n-level-or-multilevel-expandablelist – BNK Nov 04 '15 at 14:45

1 Answers1

0

Short answer, yeah you can but you really really shouldn't.

I've tried this before and it didn't end well, I can't remember the exact reasons but conflicts arise between touch listeners and the measure passes when trying to layout the views inside the different adapters don't calculate correctly.

You can find a number of custom ExpandableLists trying to do what you want around the web but I found they also had similar issues.

What I ended up doing was building my own expandable listview. If you check the source code for Android's ExpandableListView and ExpandableListAdapter you'll find that it's basically

  • just a regular listview
  • a list of items that are visible
  • an Async filter for the data source
  • some meta data to tell if its a child or group, expanded or collapsed, etc

So if all your item are collapsed the visible list only contains the Group Items. Expand a Group Item and the async filter gets triggered and populates the visible list with the Group Items and the Children of the expanded Group Item. Depending on the meta data it will call either getGroupView or getChildView.

So if you want you can take a shot at writing your own.

I wrote a blog post for an ExpandableList that I wrote that does, in theory, infinite levels of expansion. NLevelExpandableListView

triggs
  • 5,890
  • 3
  • 32
  • 31