简体   繁体   English

android listview按钮控件

[英]android listview button control

I have an android listview filled with items. 我有一个装满物品的android listview。

Every item has a button. 每个项目都有一个按钮。

This is the template of the my listview. 这是我的列表视图的模板。

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

How could i handle the click of each button in the activity code? 如何处理活动代码中的每个按钮? Each button has the same id "Button_buttontest"? 每个按钮具有相同的ID“ Button_buttontest”吗?

Thanks in advance. 提前致谢。 Best Regards. 最好的祝福。 Jose 约瑟

You would probably need to create a custom Adapter that connects a View.OnClickListener to the button when the view for the row is created. 您可能需要创建一个自定义Adapter ,以在创建行视图时将View.OnClickListener连接到按钮。 Since you're creating the OnClickListener from within the view, you'll know the position of the row that was clicked. 由于您是从视图内部创建OnClickListener的,因此您将知道被单击的行的位置。 There might be a better way, but this is the first thing that comes to mind. 也许有更好的方法,但这是第一件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM