我有三個TextViews一個ListView:如何確定哪些觀點是點擊在ListView同時處理ListView.setOnItemClickListener
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtProductName"
android:text="name"
android:textSize="17sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="0dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/txtOPrice"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtOPrice"
android:text="1.60"
android:textSize="17sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_dark"
android:clickable="true"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_toLeftOf="@+id/txtNetPrice"
android:textAlignment="center" />
<TextView
android:id="@+id/txtNetPrice"
android:text="1.61"
android:textSize="17sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
android:textStyle="bold"
android:textColor="@android:color/white"
android:layout_alignParentRight="true"
android:textAlignment="center" />
</RelativeLayout>
我處理ListView項單擊事件如下:
adapter = new productListAdapter(this,arrayListProducts);
listProducts.setAdapter(adapter);
listProducts.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//how to know which textview was clicked?
}
});
我只想知道如何確定哪些TextViews被點擊?
我是新手,搜索了很多,但什麼也沒找到。
我將不勝感激任何形式的幫助。提前致謝!
感謝您的快速回復。然而,我問的是:如果用戶點擊一個特定的textview我需要運行一堆特定的代碼,如果用戶點擊另一個我需要運行一個不同的代碼。那麼如何確定RelativeLayout中哪個TextView實際上被點擊了。 –
在這種情況下,onItemClickListener不是您要查找的內容。您需要爲每個文本視圖設置3個不同的onClickListener,並且可以使用'setTag'爲每個文本視圖設置一個標籤,因此您可以識別它們 –