0

我有一个充满项目的 android 列表视图。

每个项目都有一个按钮。

这是我的列表视图的模板。

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:paddingBottom="6dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="5px"
        android:paddingTop="5px"
        android:paddingRight="5px"
        android:gravity="left">
        <TextView android:id="@+id/TextView_test1"
            android:layout_width="200dip"
            android:paddingLeft="0px"
            android:layout_height="wrap_content"/>
        <TextView android:id="@+id/TextView_test2"
            android:layout_width="250dip"
            android:paddingLeft="0px"
            android:layout_height="wrap_content" 
            android:layout_weight="1"/>
        <TextView android:id="@+id/TextView_test3"
            android:layout_width="400dip"
            android:paddingLeft="0px"
            android:layout_height="wrap_content"  
            android:layout_weight="1"/>
        <Button
        android:id="@+id/Button_buttontest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Button_buttontest"/>
</LinearLayout>

我如何处理活动代码中每个按钮的点击?每个按钮都有相同的 id “Button_buttontest”?

提前致谢。最好的祝福。何塞

4

1 回答 1

1

在创建行视图时,您可能需要创建一个Adapter将 a 连接到按钮的自定义。View.OnClickListener由于您是在视图中创建 OnClickListener,因此您将知道被点击的行的位置。可能有更好的方法,但这是首先想到的。

于 2010-03-12T16:25:47.103 回答