Android expandable list view
Trying to create expandable list view in android. I would like each group to expand to a pre-set XML layout file. For example.
Group A { when expanded displays XML file A: buttons, seekbar, spinner and etc }
Group B { when expanded displays XML file B: buttons, seekbar, spinner and etc }
Group C { when expanded displays XML file C: buttons, seekbar, spinner and etc }
Group D { when expanded displays XML file D: buttons, seekbar, spinner and etc }
Group E { when expanded displays XML file E: buttons, seekbar, spinner and etc }
开发者_如何学运维Creating the XML file is simple. How can I display the XML file inside desired group?
If you're using a BaseExpandableListAdapter
, you can override the methods getChildTypeCount()
and getChildType()
. Then you can inflate your matching layout in getChildView()
, the parameter convertView
will then always be of the correct type.
In your example, getChildTypeCount()
would return 5 and getChildType()
could simply return the groupId.
Unfortunately you may inflate only one xml layout file that would describe your listView. Eventhough you might insert logics that would determine what kind of element is it and programmatically change it's view in getView() method of the adapter.
精彩评论