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开发者_如何学Go 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.
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.
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.
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
I think this isn't supported by Android yet ! :)
精彩评论