简体   繁体   English

在android中的可扩展列表视图中的图像图标

[英]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: 您还可以在XML中定义自己的groupIndicator:

First define your own drawable (I called it list_view_group_indicator.xml and placed it in the drawable directory) 首先定义自己的drawable(我称之为list_view_group_indicator.xml并将其放在drawable目录中)

<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的drawable

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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