我需要在可扩展列表的父视图中添加一个按钮

发布于 2024-12-19 08:05:09 字数 1251 浏览 2 评论 0原文

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

<?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 类中,但是当我尝试添加侦听器时出现空指针异常。我添加此按钮来选择/取消选择特定父级的所有子级。任何帮助都会很棒。

I am trying to add a button to the parentview of an expandablelist. This is my layout for the parentview.

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

I add the button to the java class like normal, but get a null pointer exception when i try to add a listener. I am adding this button to select/deselect all the children of the particular parent. Any help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-12-26 08:05:09

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

You can add a custom image to serve as the group drop down indicator by simply creating images of the drop down then hook it up to the expandable list view via it's group indicator property. The group indicator is a drawable xml file defining which image to use by state_expanded and drawable states. You will still need in code to set the group indicator at run time for the expandable list view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文