简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM