【问题标题】:Which button is pressed in ExpandableListView在 ExpandableListView 中按下了哪个按钮
【发布时间】:2017-05-22 10:38:57
【问题描述】:

我有一个带有 ExpandableListView 的视图,该视图具有以下视图作为其标题视图。

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

    <TextView
        android:id="@+id/lblListHeader"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="30sp"
        android:background="#ffa500"
        android:layout_weight="2"/>

    <Button android:layout_height="match_parent" android:layout_width="match_parent"
            android:id="@+id/b1" android:layout_weight="8" android:text="text" android:background="#ffa500"
            android:focusable="false" android:onClick="openChildDialog" />

</LinearLayout>

当我按下按钮时,方法openChildDialog 被调用。但是,由于根据列表标题的数量会有很多此按钮的实例,我如何知道按下的是哪个按钮实例?

编辑:这里的目的是,由于每个TextView 都有一个Button,根据按下的按钮,我想获取其对应的TextView 的文本。

请帮忙。提前致谢。

【问题讨论】:

    标签: android button expandablelistview


    【解决方案1】:

    每次使用getGroupView()方法时,你可以给你的按钮设置标签,以便以后检索和检测。

    如果您显示您的代码,我会提供更多信息。

    一个例子https://stackoverflow.com/a/31050712/1979882

    【讨论】:

      【解决方案2】:

      我真的怀疑你是否需要它(请在识别按钮后告诉我你想做什么),但如果你真的想识别按下的按钮,你可以在之后为每个按钮分配一个唯一的唯一整数或字符串您可以使用 setTag(Object object) 在适配器类中对其进行膨胀,然后在 openChildDialog() 方法中对其进行膨胀,您可以在该视图方法上使用 getTag() 取回该值。

      确保将值分配给按钮,而不是整个项目的视图。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多