Adithya
Adithya

Reputation: 2975

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.

Upvotes: 4

Views: 10005

Answers (4)

Ajay Kumar Meher
Ajay Kumar Meher

Reputation: 1952

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.

Upvotes: 14

ChrisJD
ChrisJD

Reputation: 3654

Disable the group indicator in the ExpandableListView you are using then change your group and child row layouts to include an ImageView at the start of the row. In your adapter for the ExpandableListView add logic to choose an appropriate icon to display in the ImageView.

Their is an example of this here. The example shows how to hide the expand/collapse icon for empty groups. The idea is the same for custom group/child icons, but obviously your logic will be different.

Upvotes: 2

Adithya
Adithya

Reputation: 2975

I think this isn't supported by Android yet ! :)

Upvotes: -3

harish
harish

Reputation: 255

android:groupIndicator="@drawable/roundbackground"

Check this and if you want to move the indicator then check this

http://androidcodesnips.blogspot.com/2011/07/expandable-list-view-move-group-icon.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Androidcodes+%28AndroidCodes%29

there you found moving the indicator position and example of constructing a expandable list

Upvotes: 0

Related Questions