在ExpandableListView中按下了哪个按钮

时间:2017-01-07 20:59:41

标签: android button expandablelistview

我有一个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文本{1}}。

请帮忙。提前谢谢。

2 个答案:

答案 0 :(得分:0)

每次使用getGroupView()方法时,您都可以将标记设置为按钮,以便稍后检索并检测它。

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

示例https://stackoverflow.com/a/31050712/1979882

答案 1 :(得分:0)

我真的怀疑你需要它(请在识别按钮后让我知道你想要做什么),但如果你真的想要识别按下的按钮,你可以为每个按钮分配一个唯一的唯一整数或字符串您使用protected void onStart() { Button searchrestrauntbutton = (Button)findViewById(R.id.search); searchrestrauntbutton.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { EditText area = (EditText)findViewById(R.id.area); EditText locality = (EditText)findViewById(R.id.locality); String area1 = area.getText().toString(); String locality1 = locality.getText().toString(); if(area1.equals("")) { area.setError("please enter an area"); } else if(locality1.equals("")) { locality.setError("please provide locality"); } else { Intent intentsearch = new Intent(HomePage.this,displayrestraunt.class); startActivity(intentsearch); } } }); } 在适配器类中对其进行充气,稍后在setTag(Object object)方法中,您可以使用openChildDialog()在该视图方法上获取值。

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

相关问题