Android中ListView的item點擊沒有反應的解決方法
如果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點擊沒有反應,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- Android ListView的item中嵌套ScrollView的解決辦法
- Android中Listview點擊item不變顏色及設置listselector 無效的解決方案
- Android 中ListView的Item點擊事件失效的快速解決方法
- Android ListView的OnItemClickListener詳解
- Android使用ListView批量刪除item的方法
- Android實現(xiàn)帶有邊框的ListView和item的方法
- Android 中ListView setOnItemClickListener點擊無效原因分析
- Android中ListView Item布局優(yōu)化技巧
- Android開發(fā)之ListView實現(xiàn)Item局部刷新
- Android ListView的item背景色設置和item點擊無響應的解決方法
相關文章
Android開發(fā)中方向傳感器定義與用法詳解【附指南針實現(xiàn)方法】
這篇文章主要介紹了Android開發(fā)中方向傳感器定義與用法,結合實例形式分析了Android方向傳感器的功能、定義與使用方法,并附帶基于方向傳感器實現(xiàn)指南針功能的方法,需要的朋友可以參考下2017-11-11Java Base64位編碼與String字符串的相互轉(zhuǎn)換,Base64與Bitmap的相互轉(zhuǎn)換實例代碼
這篇文章主要介紹了Java Base64位編碼與String字符串的相互轉(zhuǎn)換,Base64與Bitmap的相互轉(zhuǎn)換實例代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03Android提高之BLE開發(fā)Android手機搜索iBeacon基站
這篇文章主要介紹了BLE開發(fā)Android手機搜索iBeacon基站,需要的朋友可以參考下2014-08-08Android如何動態(tài)調(diào)整應用字體大小詳解
這篇文章主要給大家介紹了關于Android如何動態(tài)調(diào)整應用字體大小的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-05-05自定義TextView跑馬燈效果可控制啟動/停止/速度/焦點
Android自帶的跑馬燈效果不太好控制,不能控制速度,不能即時停止和啟動,而且還受焦點的影響不已,由于項目需求需所以自己寫了一個自定義的TextView,感興趣的朋友可以了解下2013-01-01