Qq friend group for Android (expandablelistview)

Source: Internet
Author: User

In project development, we may have encountered nested listview in listview, but Google suggests that we do not do this, so they have written an expandablelistview class, which inherits listview, you can implement the nested listview effect in the listview. Well, let's not talk about it. First:

 

Main Code:

 

Public class exlistview extends activity {Private Static final string group_text = "group_text"; // map keyprivate static final string child_text1 = "child_text1 "; // map the first keyprivate static final string child_text2 = "child_text2"; // map the second keylist <Map <string, string> groupdata = new arraylist <Map <string, string> (); // list of large group members <list <Map <string, string >>> childdata = new arraylist <list <Map <String, string >>> (); // group member exadapter adapter; expandablelistview exlist; // extensible listview @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // Add data for (INT I = 1; I <6; I ++) {Map <string, string> curgroupmap = new hashmap <string, string> (); groupdata. add (curgroupmap); curgroupmap. put (group_text, "" + I + ""); List <Map <string, S Tring> Children = new arraylist <Map <string, string> (); For (Int J = 1; j <6; j ++) {Map <string, string> curchildmap = new hashmap <string, string> (); children. add (curchildmap); curchildmap. put (child_text1, "" + J + ""); curchildmap. put (child_text2, "" + J + "Group Signature");} childdata. add (children);} adapter = new exadapter (exlistview. this); exlist = (expandablelistview) findviewbyid (R. id. list); exlist. setad Apter (adapter); exlist. setgroupindicator (null); // do not set the big group indicator icon, because we have set exlist. setdivider (null); // set the image to be stretched} // the key code is this extensible listview adapter class exadapter extends baseexpandablelistadapter {context; Public exadapter (context) {super (); this. context = context;} // obtain the viewpublic view getgroupview (INT groupposition, Boolean isexpanded, view convertview, viewgroup parent) {view = convertview; I F (view = NULL) {layoutinflater Inflater = (layoutinflater) getsystemservice (context. layout_inflater_service); view = Inflater. inflate (R. layout. member_listview, null);} textview Title = (textview) view. findviewbyid (R. id. content_001); title. settext (getgroup (groupposition ). tostring (); // set the name of the group member imageview image = (imageview) view. findviewbyid (R. id. tubiao); // whether to expand the arrow icon of the large group if (isexpanded) // when the large group is expanded, the image is displayed. setbac Kgroundresource (R. drawable. btn_browser2); else // image when a large group is merged. setbackgroundresource (R. drawable. btn_browser); Return view;} // obtain the idpublic long getgroupid (INT groupposition) {return groupposition;} // obtain the group name public object getgroup (INT groupposition) {return groupdata. get (groupposition ). get (group_text ). tostring ();} // obtain the total number of group members. Public int getgroupcount () {return groupdata. size ();} // obtain the viewpublic view G of the group member. Etchildview (INT groupposition, int childposition, Boolean islastchild, view convertview, viewgroup parent) {view = convertview; If (view = NULL) {layoutinflater Inflater = layoutinflater. from (context); view = Inflater. inflate (R. layout. member_childitem, null);} final textview Title = (textview) view. findviewbyid (R. id. child_text); title. settext (childdata. get (groupposition ). get (childposition ). get (CH Ild_text1 ). tostring (); // The title final textview title2 = (textview) view. findviewbyid (R. id. child_text2); title2.settext (childdata. get (groupposition ). get (childposition ). get (child_text2 ). tostring (); // Title return view;} // you can call this operation to obtain the group member idpublic long getchildid (INT groupposition, int childposition) {return childposition ;} // obtain the group member name public object getchild (INT groupposition, int childposition) {return childdata. get (gro Upposition ). get (childposition ). get (child_text1 ). tostring ();} // obtain the number of group members. Public int getchildrencount (INT groupposition) {return childdata. get (groupposition ). size ();}/*** indicates whether the child and group IDs are stable when SS changes to the * underlying data. * Indicates whether the underlying data is stably changed by the big group and group ID. * @ Return whether or not the same ID always refers to the same object * @ see adapter # hasstableids () */Public Boolean hasstableids () {return true ;} // obtain whether the group member is selected as public Boolean ischildselectable (INT groupposition, int childposition) {return true ;}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.