Reputation: 3037
I want to add an image icon in expandable list view .I have seen the tutorial they have added only in child elements .Is there any other way to add image icon in parent Any help would be appreciated. Thanks in advance.
Upvotes: 6
Views: 12828
Reputation: 1
indicator=(ImageView)convertView.findViewById(R.id.icon_img);
if ( getChildrenCount( groupPosition ) == 0 ) {
indicator.setVisibility( View.INVISIBLE );
}
else {
indicator.setVisibility( View.VISIBLE );
indicator.setImageResource( isExpanded ?
R.drawable.ic_arrow_up : R.drawable.ic_arrow_down );
}
Upvotes: 0
Reputation: 1060
You can also define your own groupIndicator in XML:
First define your own drawable (I called it list_view_group_indicator.xml and placed it in the drawable directory)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_expanded="true"
android:drawable="@drawable/packagexgeneric" />
<item
android:drawable="@drawable/packagexgenericclose" />
</selector>
Then use it as a drawable for your expandableListview
<ExpandableListView android:id="@+id/server_show_list"
android:layout_width="fill_parent"android:layout_height="wrap_content"
android:groupIndicator="@drawable/list_view_group_indicator" />
Upvotes: 13
Reputation: 213
ok
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
if(getChildrenCount(groupPosition)==0)
{
// how do i hide the group indicator ?
}
So, how can modify the group indicator for empty groups ?
Upvotes: 1
Reputation: 16357
You can try the setGroupIndicator(Drawable)
method of ExpandableListView.
Upvotes: 5