java android中可扩展列表视图中的图像图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1355771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image icon in expandable list view in android
提问by Sam97305421562
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.
我想在可扩展列表视图中添加一个图像图标。我看过他们只在子元素中添加的教程。有没有其他方法可以在父元素中添加图像图标任何帮助将不胜感激。提前致谢。
采纳答案by Dimitar Dimitrov
You can try the setGroupIndicator(Drawable)method of ExpandableListView.
你可以试试setGroupIndicator(Drawable)ExpandableListView的方法。
回答by Johnnycube
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 android:id="@+id/server_show_list"
android:layout_width="fill_parent"android:layout_height="wrap_content"
android:groupIndicator="@drawable/list_view_group_indicator" />
回答by superseed77
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 ?
那么,如何修改空组的组指示符?
回答by shashi patil
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 );
}

