Determine which element triggered OnItemClickListener
I have got a listview with 2 textviews inside it. I have set up my OnItemClickListener which works fine. However, I was wondering how to determine whether the OnItemClickListener was triggered by TextView01 or TextView02?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:gravity="left|center"
android:layout_width="wrap_content" android:paddingBottom="5px"
android:paddingTop="5px" android:paddingLeft="5px">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:background开发者_开发问答="@drawable/bg" android:textColor="#FFFF00"
android:text="hi"></TextView>
<TextView android:text="@+id/TextView02" android:id="@+id/TextView02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="10px" android:textColor="#0099CC"></TextView>
</LinearLayout>`
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
}
});
onitemClickListener
is not triggered by click on textview. onItemClickLister()
is a callback listener for listview; it is called when user click on list view.
To get click event on textview add clicklistener to textview. You will get its callback in OnclickListener(view v)
.
精彩评论