我創建了一個列表視圖與自定義列表行。該列表行包含四個imagebuttons一個圖像視圖:Android自定義列表按鈕onclick索引
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:padding="2dip"
android:id="@+id/list_image"
android:layout_width="match_parent"
android:layout_height="200dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/test"
android:scaleType="centerCrop"/>
<LinearLayout
android:paddingTop="5dip"
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/list_image"
android:layout_alignRight="@+id/list_image"
android:layout_below="@+id/list_image"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/copyLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/copy"
android:background="@color/white"
/>
<ImageButton
android:id="@+id/visitHP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/website"
android:background="@color/white" />
<ImageButton
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/delete"
android:background="@color/white" />
<ImageButton
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_social_share"
android:background="@color/white" />
</LinearLayout>
作爲一個PIC:
現在我想添加到每個的按鈕onclicklistener在哪裏我可以得到該行或對象o的索引f行。
我試圖實現OnClickListener我ArrayAdapter:
ImageButton btn = (ImageButton) convertView.findViewById(R.id.delete);
btn.setOnClickListener(this);
public void onclick(View v) {
int img = v.getId();
}
但是有了這個,我不會得到該行的索引。
我該如何處理這個問題?由於
感謝一個聰明的想法和它的工作 – dontcare
令人驚歎!我正在尋找某種「數據」字段,「標籤」這樣做了...... –