Android中ListView的item點(diǎn)擊沒(méi)有反應(yīng)的解決方法
如果stu_item.xml里面包括button或者checkbox等控件,默認(rèn)情況下list的item會(huì)失去焦點(diǎn),導(dǎo)致無(wú)法響應(yīng)item的事件,最常用的解決辦法是在stu_item.xml的布局文件中設(shè)置descendantFocusability屬性。
該屬性是當(dāng)一個(gè)為view獲取焦點(diǎn)時(shí),定義viewGroup和其子控件兩者之間的關(guān)系。
屬性的值有三種:
beforeDescendants:viewgroup會(huì)優(yōu)先其子類(lèi)控件而獲取到焦點(diǎn) afterDescendants:viewgroup只有當(dāng)其子類(lèi)控件不需要獲取焦點(diǎn)時(shí)才獲取焦點(diǎn) blocksDescendants:viewgroup會(huì)覆蓋子類(lèi)控件而直接獲得焦點(diǎn) <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"><!--添加這個(gè)屬性--> <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>
效果圖:
總結(jié)
以上所述是小編給大家介紹的Android中ListView的item點(diǎn)擊沒(méi)有反應(yīng),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android ListView的item中嵌套ScrollView的解決辦法
- Android中Listview點(diǎn)擊item不變顏色及設(shè)置listselector 無(wú)效的解決方案
- Android 中ListView的Item點(diǎn)擊事件失效的快速解決方法
- Android ListView的OnItemClickListener詳解
- Android使用ListView批量刪除item的方法
- Android實(shí)現(xiàn)帶有邊框的ListView和item的方法
- Android 中ListView setOnItemClickListener點(diǎn)擊無(wú)效原因分析
- Android中ListView Item布局優(yōu)化技巧
- Android開(kāi)發(fā)之ListView實(shí)現(xiàn)Item局部刷新
- Android ListView的item背景色設(shè)置和item點(diǎn)擊無(wú)響應(yīng)的解決方法
相關(guān)文章
Android實(shí)現(xiàn)彈出鍵盤(pán)的方法
這篇文章主要介紹了Android實(shí)現(xiàn)彈出鍵盤(pán)的方法,是非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09Android使用AIDL實(shí)現(xiàn)兩個(gè)App間通信
這篇文章主要為大家詳細(xì)介紹了Android使用AIDL實(shí)現(xiàn)兩個(gè)App間通信,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04Android開(kāi)發(fā)中方向傳感器定義與用法詳解【附指南針實(shí)現(xiàn)方法】
這篇文章主要介紹了Android開(kāi)發(fā)中方向傳感器定義與用法,結(jié)合實(shí)例形式分析了Android方向傳感器的功能、定義與使用方法,并附帶基于方向傳感器實(shí)現(xiàn)指南針功能的方法,需要的朋友可以參考下2017-11-11Java Base64位編碼與String字符串的相互轉(zhuǎn)換,Base64與Bitmap的相互轉(zhuǎn)換實(shí)例代碼
這篇文章主要介紹了Java Base64位編碼與String字符串的相互轉(zhuǎn)換,Base64與Bitmap的相互轉(zhuǎn)換實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03詳解Flutter?響應(yīng)式狀態(tài)管理框架GetX
這篇文章主要為大家介紹了Flutter?響應(yīng)式狀態(tài)管理框架GetX詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Android提高之BLE開(kāi)發(fā)Android手機(jī)搜索iBeacon基站
這篇文章主要介紹了BLE開(kāi)發(fā)Android手機(jī)搜索iBeacon基站,需要的朋友可以參考下2014-08-08Android如何動(dòng)態(tài)調(diào)整應(yīng)用字體大小詳解
這篇文章主要給大家介紹了關(guān)于Android如何動(dòng)態(tài)調(diào)整應(yīng)用字體大小的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05自定義TextView跑馬燈效果可控制啟動(dòng)/停止/速度/焦點(diǎn)
Android自帶的跑馬燈效果不太好控制,不能控制速度,不能即時(shí)停止和啟動(dòng),而且還受焦點(diǎn)的影響不已,由于項(xiàng)目需求需所以自己寫(xiě)了一個(gè)自定義的TextView,感興趣的朋友可以了解下2013-01-01