Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group Indicators in android.widget.ExpandableListView

I have to populate an ExpandableListView in my application. ExpandableListView consists of a set of groups which in turn consists of a set of children.

For e.g.

** Group1

...ChildA

...ChildB

Group2

...ChildC
...ChildD

. . .

GroupN

...ChildM1
...ChildM2**

By default the Groups have an arrow indicator to the left. I wanted to change that arrow indicator to an image icon. I want to set a different image icon for each group. For example,

Group1 will have a tree icon. Group2 will have an animal icon and so on.

Is it also possible to have a different icon indicator for each child in each group ? If yes i would be glad to have some guidance on that too.

I have tried many approaches but haven't been successful. Is it something to do with the emulator support as i am running my application on the emulator.

Looking forward to your help.

Thanks, Adithya.

like image 524
Adithya Avatar asked Dec 13 '22 09:12

Adithya


1 Answers

Use android:groupIndicator like,

<ExpandableListView ...
    android:groupIndicator="@drawable/group_indicator" >

group_indicator.xml can be a selector to show a different arrow(state) if the item is expanded or collapsed:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_empty="true" android:drawable="@drawable/collapsed_drawable" />
    <item android:state_expanded="true" android:drawable="@drawable/expanded_drawable" />
</selector>

Or in code like,


expandableView.setGroupIndicator(context.getResources().getDrawable(
                    R.drawable.group_indicator));

Hope, this will help you.

like image 71
Ajay Kumar Meher Avatar answered Dec 28 '22 06:12

Ajay Kumar Meher