Description of the Expandablelistview (expandable list component) and its usage

Source: Internet
Author: User
Tags xml attribute

The usage of Expandablelistview is very similar to the ListView, except that the list item shown should be provided by Expandablelistadapter, and the following is its XML attribute and description:

However, the next step is to speak with the facts:

--------------------------------------------------------------------------------

1, the project layout file is very simple, and the ListView is similar to, here does not post code.

2, Expandablelistviewactivity.java key code is as follows:

(to define a global private listview variable)

ListView =new  myexpandablelistadapter (); Listview.setadapter (adapter);

3. The Myexpandablelistadapter code is as follows:

 Public classMyexpandablelistadapter implements Expandablelistadapter {int[] Logos =New int[]{R.drawable.word, R.drawable.excel, R.drawable.email, r.drawable.ppt    }; Privatestring[] Armtypes =Newstring[]{"WORD","EXCEL","EMAIL","PPT"    }; PrivateString[][] Arms =Newstring[][]{{"Document editing","Document Layout","Document Processing","Document Printing"},            {"Table Editing","Table Layout","Table Processing","Form Printing"},            {"send and receive mail","Manage Mailboxes","Login Log Out","Registering Bindings"},            {"Presentation Editing","Presentation Layout","Presentation Processing","Demo Print"},    }; @Override Public voidRegisterdatasetobserver (Datasetobserver observer) {} @Override Public voidUnregisterdatasetobserver (Datasetobserver observer) {} @Override Public intGetGroupCount () {returnarmtypes.length; } @Override Public intGetchildrencount (intgroupposition) {        returnarms[groupposition].length; } @Override PublicObject Getgroup (intgroupposition) {        returnArmtypes[groupposition]; } @Override PublicObject Getchild (intGroupposition,intchildposition) {        returnArms[groupposition][childposition]; } @Override Public LongGetgroupid (intgroupposition) {        returngroupposition; } @Override Public LongGetchildid (intGroupposition,intchildposition) {        returnchildposition; } @Override PublicBoolean hasstableids () {return true; } @Override PublicView Getgroupview (intgroupposition, Boolean isexpanded, View Convertview, ViewGroup parent) {LinearLayout ll=NewLinearLayout (expandablelistviewactivity. This);        Ll.setorientation (linearlayout.horizontal); ImageView logo=NewImageView (expandablelistviewactivity. This);        Logo.setimageresource (Logos[groupposition]); Logo.setpadding ( $, the,0,0);        Ll.addview (logo); TextView TextView=Gettextview ();        Textview.settext (Getgroup (groupposition). toString ()); Textview.setpadding (Ten,0,0,0);        Ll.addview (TextView); returnll; } @Override PublicView Getchildview (intGroupposition,intchildposition, Boolean islastchild, View Convertview, ViewGroup parent) {TextView TextView=Gettextview ();        Textview.settext (Getchild (Groupposition, childposition). toString ()); returnTextView; } @Override PublicBoolean ischildselectable (intGroupposition,intchildposition) {        return true; } @Override PublicBoolean areallitemsenabled () {return false; } @Override PublicBoolean isEmpty () {return false; } @Override Public voidOngroupexpanded (intgroupposition) {} @Override Public voidOngroupcollapsed (intgroupposition) {} @Override Public LongGetcombinedchildid (LongGroupId,LongchildID) {        return 0; } @Override Public LongGetcombinedgroupid (LonggroupId) {        return 0; }    PrivateTextView Gettextview () {abslistview.layoutparams LP=NewAbslistview.layoutparams (ViewGroup.LayoutParams.FILL_PARENT, -); TextView TextView=NewTextView (expandablelistviewactivity. This);        TEXTVIEW.SETLAYOUTPARAMS (LP); Textview.setgravity (gravity.center_vertical|gravity.left); Textview.setpadding ( $,0,0,0); Textview.settextsize ( -); returnTextView; }}

The code does not have much comment on it, here is a description:

There are two key methods of the adapter: Getchildview () and Getgroupview ();

----------The former return view object as a child list item, which returns the view as a group list item.

4, the following is the operating interface of the program:

Description of the Expandablelistview (expandable list component) and its usage

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.