我想在自定义的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>
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误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代替颜色/透明.
如何完全隐藏群组指标?
编辑:事实证明,该代码可以工作...如果你把它放在drawable资源文件夹而不是布局.
我刚刚尝试了当前的Google示例ExpandableListiew:
这个样本看起来非常简单易用,但我想做的是说其中一个类别没有孩子.我删除了所有孩子,但问题是箭头仍然出现在当前行上.
例如,假设我删除了所有"Cat Names",箭头仍在那里,当我点击它时,箭头就会改变.如何删除此箭头并启动活动?
隐藏无子女群体的指标
main.xml中
<ExpandableListView
android:id="@+id/elv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:groupIndicator="@drawable/selector">
</ExpandableListView>
Run Code Online (Sandbox Code Playgroud)
selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_empty="true" android:drawable="@android:color/transparent"/>
<item android:state_expanded="true" android:drawable="@drawable/expanded" />
<item android:drawable="@drawable/collapse" />
</selector>
Run Code Online (Sandbox Code Playgroud)
它对我的ICS不起作用,似乎所有崩溃组的状态都是空的
我ExpandableListView在android中创建了一个。我有一些类别,其中还有更多子类别。而其他则没有子类别。如果图标没有子类别,如何删除它?
例如,我有一个类别,如“主页”、“纱丽”等。在“主页”中,没有子类别,因此我需要删除可展开的展开图标。
这是我的content_home.xml,它有一个ExpandableListView
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.domore.onlineangelnx.Home"
tools:showIn="@layout/activity_home">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ExpandableListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
<!--android:choiceMode="singleChoice"-->
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的drawable_list_item.xml,有一个TextView显示ExpandableListView标题
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@color/list_item_title"
android:gravity="center_vertical" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的ExpandableListViewAdapter,它计算项目及其子项目
package adapter;
import android.content.Context;
import android.graphics.Typeface;
import …Run Code Online (Sandbox Code Playgroud)