简体   繁体   中英

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.

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" />

您可以尝试ExpandableListView的setGroupIndicator(Drawable)方法。

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 ?

    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 );
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM