如何完全隐藏ExpandableListView的groupIndicator?

69

我希望能够完全隐藏自定义ExpandableListView中的groupIndicator。

这里提供的示例在这里似乎没有起作用。

它建议创建一个选择器并使用expList.setGroupIndicator(selector),我进行了复制:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/empty_icon">
    <item android:state_empty="true" android:drawable="@android:color/transparent"/>
    <item android:state_expanded="true" android:drawable="@android:color/transparent" />
    <item android:drawable="@android:color/transparent" />
</selector>

这会导致以下错误
ERROR/AndroidRuntime(10675): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b0013}

使用android:id/empty代替color/transparent也会给出相同的建议。
如何完全隐藏组指示器?
编辑:事实证明,如果将该代码放在drawable资源文件夹中而不是layout中,则该代码确实有效。
3个回答

248

你尝试过更改ExpandableListView的属性android:groupIndicator="@null"吗?


20
对于任何想要以编程方式完成此操作的人,可以使用 mExpandableListView.setGroupIndicator(null) 完成。 - Phil

0
你可以尝试这段代码: listView = (ExpandableListView) view.findViewById(R.id.listView);
listView.setGroupIndicator(null);


listView.setChildIndicator(null);

0

我曾经遇到过同样的问题,这个方法解决了我的问题。 在你的ListView的适配器中,在getGroupView方法中添加以下代码。

if (groupPosition == 0) {
     convertView = layoutInflater.inflate(R.layout.blank_layout, null);

} else {
    convertView = layoutInflater.inflate(R.layout.group_indicator_cell,null);
}

这将清空列表的第0组。

其中,空白布局是一个包含一些视图的布局,其layout_height=0dp。它有效!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接