Sam97305421562
Sam97305421562

Reputation: 3037

Image icon in expandable list view in android

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

Answers (4)

shashi patil
shashi patil

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

Johnnycube
Johnnycube

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

superseed77
superseed77

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

Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 16357

You can try the setGroupIndicator(Drawable) method of ExpandableListView.

Upvotes: 5

Related Questions