2009-08-31 91 views

回答

5

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

+0

嗨, 这种方法增加了图标给所有父母,但是如果我想为每个父母分别添加单独的图标。是否有可能。 – Sam97305421562 2009-08-31 11:28:26

+0

如果你想真正地定制你的组布局,为什么你不尝试使用或继承SimpleExpandableListAdapter?为expandedGroupLayout设置自定义资源,并在getGroupView(int,boolean,View,ViewGroup)上加载所需的图像。祝您好运,并在您看到/尝试时回复评论。 – 2009-08-31 12:40:03

1

确定

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, 
      ViewGroup parent) { 

    if(getChildrenCount(groupPosition)==0) 
    { 
      // how do i hide the group indicator ? 

    } 

那么,怎样才能修改空组组指标?

13

您也可以在XML定义自己的groupIndicator:

首先定义自己的绘制(我list_view_group_indicator.xml称之为并将其放置在绘制目录)

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

然后把它作为一个绘制您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" /> 
+0

它的工作原理,谢谢 – 2013-11-13 09:42:46

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