在listview的item中包含有textview和checkBox。我們既想獲取listitem的點擊事件,又想獲取listitem中textview的點擊事件和listitem中checkBox的點擊事件,那麼有沒有辦法實現呢?答案是肯定的,我們只需重新創建listview的適配器繼承BaseAdpter就可以了。另外如果有checkBox或者imageview在內的話就必須設置它聚焦爲false。
關鍵點:
2.checkBox或者imageview在內的話就必須設置它聚焦爲false。 android:focusable="false"
我的Item佈局中的checkbox如下:
<CheckBox
android:id="@+id/address_item_checkbox"
style="@style/custom_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:checked="false"
android:focusable="false"
android:visibility="gone" />
<!--加android:focusable="false"這句的原因是因爲checkBox的點擊事件優先級高於listview的點擊事件,所以要屏蔽之-->
解決了我的問題! 做個小筆記,希望對其他人也有一個幫助