2010-03-12 71 views
0

我有一個android項目列表視圖。android 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> 

我該如何處理活動代碼中每個按鈕的點擊? 每個按鈕都有相同的ID「Button_buttontest」?

在此先感謝。 最好的問候。 Jose

回答

1

當創建行的視圖時,您可能需要創建一個自定義Adapter,將View.OnClickListener連接到該按鈕。由於您在視圖中創建了OnClickListener,因此您將知道被點擊的行的位置。可能有更好的辦法,但這是首先想到的。