Android——事件冲突处理

当我们给列表的item设置了点击事件后,又给item中的按钮设置了点击事件,此时item的点击事件会失效。

解决

给item的布局xml中设置以下属性

java 复制代码
  android:descendantFocusability="blocksDescendants"
xml 复制代码
   <LinearLayout 
   	xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_item"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:orientation="horizontal">

在dapter中通过 setDescendantFocusability 设置

java 复制代码
	holder.ll_item.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);

案例代码

相关推荐
巧克力芋泥包37 分钟前
前端使用阿里云图形验证码;并且与安卓进行交互
android·前端·阿里云
Just_Paranoid4 小时前
【MQTT】基于 Android 设备接入物联网平台最佳实践
android·mqtt·eclipse·iot·paho·mqtt.fx
alexhilton7 小时前
深入理解withContext和launch的真正区别
android·kotlin·android jetpack
TDengine (老段)10 小时前
TDengine 转换函数 TO_JSON 用户手册
android·大数据·数据库·json·时序数据库·tdengine·涛思数据
q***428210 小时前
SpringCloudGateWay
android·前端·后端
卫生纸不够用10 小时前
Appium-锁屏-Android
android·appium
阿拉斯攀登10 小时前
安卓工控机 OTA 升级方案(SpringBoot+MQTT)
android·spring boot·物联网·iot
顾林海11 小时前
从0到1搭建Android网络框架:别再让你的请求在"路上迷路"了
android·面试·架构
花花鱼11 小时前
android room中实体类变化以后如何迁移
android
Jomurphys12 小时前
设计模式 - 适配器模式 Adapter Pattern
android