I'm currently working on a project in which I need something like the following:
- MainGroup 1 (Expandable)
- SubGroup 1 (Expandable)
- SubSubGroup 1 (Expandable)
- Child View
- Child View
- ...
- SubSubGroup 2 (Expandable)
- Child View
- Child View
- ...
- SubGroup 2 (Expandable)
- SubSubGroup 3 (Expandable)
- Child View
- ...
- SubSubGroup 4 (Expandable)
- Child View
- ...
- SubGroup 3 (Expandable)
- Child View
- ...
- MainGroup 2 (Expandable)
- ...
At most it would be an ExpandableListView
inside an ExpandableListView
inside an ExpandableListView
- so 3 layers of ExpandableListView
:
MainGroup
would only hold other ExpandableListView
.
SubGroup
would hold other ExpandableListView
except for the last two, which will allways just be ChildViews
. (I'm thinking those two could just be substituted with the one for SubSubGroup
)
SubSubGroup
would allways hold ChildViews
.
My problem is that I think I fail to understand the basic principles of how the ExpandableListView
layouts it's children. I've looked at examples like this, but can't get my head around the functionality.
I've tried simply adding an ExpandableListView
as a child in another - but something doesn't work as only the first item of the inner ExpandableListView
is visible if you expand one of the outer groups. I can however by setting the height of the outer groups container manually make it big enough to show all items in the inner ExpandableListView
. To be optimal, calculation of height should of course be done on the fly.
So, to get to some more solid questions:
- Can someone give me an explanation of the
ExpandableListView
"lifecycle" (by this I mean instantation, re-use of views, expand/collapse listeners) including:
- How and when is an
ExpandableListView
notified that a child is expanded/collapsed?
- How does the
ExpandableListView
know how much space to make for all children to fit into a group container?
- How much benefit is there in using the
ExpandableListView
to create the above, compared to just mixing together my own solution using some LinearLayouts
and some OnClickListeners
?
Edit
For my last question I might note that there can be anywhere from 1 to 20+ MainGroups
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…