【问题标题】:I need a button in the parent view of an expandablelist我需要一个可展开列表的父视图中的按钮
【发布时间】:2012-01-28 18:28:36
【问题描述】:

我正在尝试向可展开列表的父视图添加一个按钮。这是我的父视图布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/explist_indicator"
        android:layout_width="25dp"
        android:layout_height="match_parent"
        android:layout_weight=".25"
        android:src="@drawable/expander_group" />

    <TextView
        android:id="@+id/contacts"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:paddingLeft="20dp"
        android:text="@string/contacts"
        android:textSize="28dp" >
    </TextView>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/plus"
        android:text="Button" />

</LinearLayout>

我像往常一样将按钮添加到 java 类,但是当我尝试添加侦听器时出现空指针异常。我正在添加这个按钮来选择/取消选择特定父母的所有孩子。任何帮助都会很棒。

【问题讨论】:

  • 您还需要发布一些代码 - 以及您的 LogCat。

标签: android expandablelistview


【解决方案1】:

您可以添加自定义图像作为组下拉指示器,只需创建下拉列表的图像,然后通过其组指示器属性将其连接到可展开的列表视图。组指示符是一个可绘制的 xml 文件,定义 state_expanded 和可绘制状态使用哪个图像。您仍然需要在代码中为可扩展列表视图在运行时设置组指示器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 2023-03-07
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    相关资源
    最近更新 更多