Android 15th Lesson--expandablelistview

Source: Internet
Author: User

Abslistview.layoutparams lp=new Abslistview.layoutparams (viewgroup.layoutparams.match_parent,64);
The meaning of this sentence is to create an instance of the layout (LAYOUTPARAMS) LP.
Abslistview.layoutparams (viewgroup.layoutparams.match_parent,64) specifies the width and height of the layout;
-1 represents layoutparams.match_parent, that is, the size of the layout will fill its parent control;
-2 represents layoutparams.wrap_content, i.e. the size of the layout will be the size of its own content;
Here is the usage of Baseexpandablelistadapter
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">   <ExpandablelistviewAndroid:id= "@+id/list"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:childindicator= "@drawable/ic_launcher"    /></LinearLayout>
 PackageCom.example.expandablelistview;Importandroid.app.Activity;ImportAndroid.app.ActionBar;Importandroid.app.Fragment;ImportAndroid.content.Context;ImportAndroid.os.Bundle;Importandroid.view.Gravity;ImportAndroid.view.LayoutInflater;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.AbsListView;ImportAndroid.widget.BaseExpandableListAdapter;ImportAndroid.widget.ExpandableListAdapter;ImportAndroid.widget.ExpandableListView;ImportAndroid.widget.ImageView;Importandroid.widget.LinearLayout;ImportAndroid.widget.TextView;ImportAndroid.os.Build; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //Create a Baseexpandablelistadapter objectExpandablelistadapter adapter=NewBaseexpandablelistadapter () {int[] logos=New int[]{r.drawable.p,r.drawable.z,r.drawable.t}; PrivateString[] Armtypes=Newstring[]{"Protoss class", "Zerg Class", "Terran Class"                }; PrivateString[][] Arms=Newstring[][]{{"Berserker", "Dragon Knight", "Dark Chapel", "Soldiers of"},                    {"Puppy", "Thorn Snake", "dragon", "self-destruct plane"},                    {"Gunner", "Nurse mm", "phantom"}            }; @Override Public intGetGroupCount () {returnarms.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 Public BooleanHasstableids () {return true; } @Override PublicView Getgroupview (intGroupposition,Booleanisexpanded, View Convertview, ViewGroup parent) {LinearLayout ll=NewLinearLayout (mainactivity. This); Ll.setorientation (0); ImageView logo=NewImageView (mainactivity. This);                Logo.setimageresource (Logos[groupposition]);                Ll.addview (logo); TextView TextView=Gettextview ();                Textview.settext (Getgroup (groupposition). toString ());                Ll.addview (TextView); returnll; }            PrivateTextView Gettextview () {abslistview.layoutparams LP=NewAbslistview.layoutparams (viewgroup.layoutparams.match_parent,64); TextView TextView=NewTextView (mainactivity. This);                TEXTVIEW.SETLAYOUTPARAMS (LP); Textview.setgravity (gravity.center_vertical|gravity.left); Textview.setpadding (36, 0,0,0); Textview.settextsize (20); returnTextView; } @Override PublicView Getchildview (intGroupposition,intChildposition,BooleanIslastchild, View Convertview, ViewGroup parent) {TextView TextView=Gettextview ();                Textview.settext (Getchild (groupposition,childposition). toString ()); returnTextView; } @Override Public BooleanIschildselectable (intGroupposition,intchildposition) {                return true;        }                    }; Expandablelistview Expandableview=(Expandablelistview) Findviewbyid (r.id.list);    Expandableview.setadapter (adapter); }}

Android 15th Lesson--expandablelistview

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.