Properties of Android Expandablelistview (group not expanded)

Source: Internet
Author: User

1. The setting Expandablelistview is expanded by default:
First instantiate the Exlistview and then

    Exlistview.setadapter (exlvadapter);        // Traverse All group, set all items to the default expansion       Intgroupcount = exlistview.getcount ();         for (inti=0; i<groupcount; i++)       {              Exlistview.expandgroup (i);       };   

2. Remove the Expandablelistview default arrow
When used to Expandablelistview, there is an arrow icon system comes with your custom layout can not be removed as long as you set a property, as follows:
Settinglists.setgroupindicator (NULL); ~~~~~~~~~~~~~~~~~ Here is the custom arrow icon set. The empty is gone.
can also be customized (but the location is not recommended in that place) as follows:
First, customize a Expandablelistviewselector.xml file with the following details: Java code

<?xml version="1.0"encoding="Utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_expanded="true"android:drawable="@drawable/expandablelistviewindicatordown"/> <item android:drawable="@drawable/expandablelistviewindicator"/> </selector>

Add a code like this:

    Settinglists.setgroupindicator (this. Getresources (). Getdrawable ( R.layout.expandablelistviewselector));        or XML settings:          android:groupindicator="@drawable/groupindicator_selector"  

3. Change the default arrows to the right to display:

1 First Expandablelistviewelistview;

Elistview.setgroupindicator (null);//Remove the default left arrow of the control,

2 There is a way to customize the adapter that inherits from Baseexpandablelistadapter

    /** * Parent View*/
@Override
PublicView Getgroupview (intgroupposition, booleanisexpanded, view Convertview, ViewGroup parent) {LOG.I ("Zhaoxiong","Parent View"); Linearlayoutparentlayout= (linearlayout) view.inflate (context, R.layout.wowocoupons_parent_item,NULL); Textviewparenttextview=(TextView) Parentlayout.findviewbyid (R.id.parentitem); Parenttextview.settext (parentlist.Get(groupposition)); Imageviewparentimageviw=(ImageView) Parentlayout.findviewbyid (R.id.arrow); //Judging isexpanded can be controlled by pressing or closing, while changing the picture if(isexpanded) {parentimageviw.setbackgroundresource (R.drawable.arrow_down); }Else{parentimageviw.setbackgroundresource (r.drawable.arrow_up);} returnparentlayout; }

Expandablelistview Response Ongroupclick Listen: Set Expandablelistview.setongroupclicklistener ()
Collapse and expand Events, you can set Setongroupcollapselistener and Setongroupexpandlistener

The Expandablelistview contains multiple group, and when you want to expand a group, the other group shuts down:

    Exlist.setongroupexpandlistener (new  Ongroupexpandlistener () {                        @Override                public  void ongroupexpand (int  groupposition) {                    for (int0) ; I < GetData (). Size (); i++) {                        if (groupposition! = i) {                            exlist.collapsegroup (i);}}                        }                    });  

3.expandablelistview Group Click event, Ongroupclick return value false expand, true does not expand

Tt_list.setongroupclicklistener (NewOngroupclicklistener () {@Override PublicBoolean Ongroupclick (expandablelistview parent, View V,intGroupposition,LongID) {Isflag=true; if(Adapter.getgroupdata ().Get(groupposition). GetList (). Size () = =1) {Bundle b=NewBundle (); B.putint ("Saveindex",0); //b.putstring ("Mac", Mac); //b.putstring ("DeviceId", Mdeviceid); B.putserializable ("DataList", Adapter.getgroupdata ().Get(groupposition). GetList ()); Intent I=NewIntent (wappushbindingactivity. This, Videoplayeractivity.class);                       I.putextras (b);                  StartActivity (i); }  //int groupcount = Tt_list.getcount (); //for (int i=0; i<groupcount; i++) {//if (i!=groupposition)//Tt_list.collapsegroup (i); //               }; //log.v ("Xulongheng*wappushbind*tt_list", "Ongroupclick:" +previousx+ "/" +previousy ");                 return true;//The default is False, when set to True, click events do not expand group            }          }); 

Properties of Android Expandablelistview (group not expanded)

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.