Baseexpandablelistadapter can be used to implement a so-called foldable list, such as the function of grouping friends in QQ.
The basic principles of baseexpandablelistadapter and baseadapter are the same, except that two groups are required when the list is imported. One group is grouparray and the other is childarray, the former is used for group names (like QQ friends, classmates, and friends), and each element of the latter is a set of sub-data (similar to the set of Zhang San and Li Si of QQ students) to implement Adapter
Public Class Expandableadapter Extends Baseexpandablelistadapter { Private Shortlist <teachersumgroupsmodel> Grouparray; Private List <shortlist <teachersumgroupdetailmodel> Childarray; Private Context context; Private Layoutinflater Inflater; Public Expandableadapter (context, inclulist <teachersumgroupsmodel> Coursegrouplist, list <Shortlist <teachersumgroupdetailmodel> Childarray) {Inflater = (Activity) Context). getlayoutinflater (); This . Grouparray = Coursegrouplist; This . Childarray = Childarray ;} Public Int Getgroupcount (){ // Todo auto-generated method stub Return Grouparray. Size ();} Public Int Getchildrencount ( Int Groupposition ){ // Todo auto-generated method stub Return Childarray. Get (groupposition). Size ();} Public Object getgroup ( Int Groupposition ){ // Todo auto-generated method stub Return Grouparray. Get (groupposition );} Public Object getchild ( Int Groupposition, Int Childposition ){ // Todo auto-generated method stub Return Childarray. Get (groupposition). Get (childposition );} Public Long Getgroupid ( Int Groupposition ){ // Todo auto-generated method stub Return Groupposition ;} Public Long Getchildid ( Int Groupposition, Int Childposition ){ // Todo auto-generated method stub Return Childposition ;} Public Boolean Hasstableids (){ // Todo auto-generated method stub Return False ;} Public View getgroupview ( Int Groupposition, Boolean Isexpanded, view convertview, viewgroup parent ){ // Todo auto-generated method stub Textview title; If (Convertview = Null ) {Convertview = Inflater. Inflate (R. layout. simple_listview_item, parent, False );} Title = (Textview) convertview. findviewbyid (R. Id. simple_listview_textview); string t = "" + Grouparray. Get (groupposition). getname (); title. settext (t ); Return Convertview ;} Public View getchildview ( Int Groupposition, Int Childposition, Boolean Islastchild, view convertview, viewgroup parent ){ // Todo auto-generated method stub Textview title; If (Convertview = Null ) {Convertview = Inflater. Inflate (R. layout. simple_listview_item, parent, False );} Title =(Textview) convertview. findviewbyid (R. Id. simple_listview_textview); string account = Childarray. Get (groupposition). Get (childposition). getaccount (); string name = Childarray. Get (groupposition). Get (childposition). getname (); string t = Account + "" + Name; log. E ( "Sumlist", "info is" + T); title. settext (t ); Return Convertview ;} Public Boolean Ischildselectable (Int Groupposition, Int Childposition ){ // Todo auto-generated method stub Return True ;}}
CodeFrom a current project.
Similar to the key getview method of baseadapter, The getgroupview and getchildview methods are important here. In fact, the internal implementation is similar.