Android expandablelistview special attributes

Source: Internet
Author: User

1. Set expandablelistview to expand by default.:

Instantiate exlistview first

Then

Exlistview. setadapter (exlvadapter );

// Traverse all groups and set all items to expand by default

Int groupcount = exlistview. getcount ();

For (INT I = 0; I <groupcount; I ++ ){

Exlistview. expandgroup (I );

};

 

2. Remove the default arrow of expandablelistview.

When using expandablelistview, there is an arrow icon that comes with the system. In your custom layout, you cannot just set an attribute, as shown below:

Settinglists. setgroupindicator (null );~~~~~~~~~~~~~~~~~ This is to set a custom Sequence Graph. If this parameter is set to null, no more.

It can also be customized (but the location is not recommended in that place) as follows:

First, customize an expandablelistviewselector. xml file. The specific content is as follows:
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 the following code:

Settinglists. setgroupindicator (this. getresources (). getdrawable (R. layout. expandablelistviewselector ));

Success

3. Change the default arrow to display on the right:

1 first, expandablelistview elistview;

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

2. There is a method in the Custom adapter that inherits from baseexpandablelistadapter.

/**
* Parent Class View
*/
@ Override
Public View getgroupview (INT groupposition, Boolean isexpanded,
View convertview, viewgroup parent ){
Log. I ("zhaoxiong", "parent View ");
Linearlayout parentlayout = (linearlayout) view. Inflate (context, R. layout. wowocoupons_parent_item, null );
Textview parenttextview = (textview) parentlayout. findviewbyid (R. Id. parentitem );
Parenttextview. settext (parentlist. Get (groupposition ));
Imageview parentimageviw = (imageview) parentlayout. findviewbyid (R. Id. Arrow );

// Determine whether isexpanded can be used to control whether to press or close, and change the image at the same time
If (isexpanded ){
Parentimageviw. setbackgroundresource (R. drawable. arrow_down );
} Else {
Parentimageviw. setbackgroundresource (R. drawable. arrow_up );
}

Return parentlayout;
}

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.