【问题标题】:android listview button controlandroid listview按钮控件
【发布时间】:2010-03-12 15:09:56
【问题描述】:

我有一个充满项目的 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”?

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

【问题讨论】:

    标签: java android android-widget


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-12-08
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多