如果stu_item.xml里面包括button或者checkbox等控件,默認情況下list的item會失去焦點,導致無法響應item的事件,最常用的解決辦法是在stu_item.xml的布局文件中設置descendantFocusability屬性。
該屬性是當一個為view獲取焦點時,定義viewGroup和其子控件兩者之間的關系。
屬性的值有三種:
beforeDescendants:viewgroup會優(yōu)先其子類控件而獲取到焦點 afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點 blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" android:descendantFocusability="blocksDescendants"><!--添加這個屬性--> <ImageView android:id="@+id/img_head" android:layout_width="50dp" android:layout_height="50dp" android:src="@drawable/dog2" android:scaleType="centerCrop" android:layout_marginRight="5dp"/> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:id="@+id/tv_name"/> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:id="@+id/tv_age"/> <Button android:id="@+id/btn_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="刪除" android:textColor="#ffffff" android:background="#ff0000" /> </LinearLayout>
當前題目:Android中ListView的item點擊沒有反應的解決方法-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://aaarwkj.com/article42/dohohc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、軟件開發(fā)、用戶體驗、手機網(wǎng)站建設、營銷型網(wǎng)站建設、品牌網(wǎng)站設計
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)