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);

案例代码

相关推荐
TA远方8 小时前
【Android】adb常用的命令用法详解
android·adb·管理·控制·命令
贺biubiu16 小时前
2025 年终总结|总有那么一个人,会让你千里奔赴...
android·程序员·年终总结
xuekai2008090116 小时前
mysql-组复制 -8.4.7 主从搭建
android·adb
nono牛17 小时前
ps -A|grep gate
android
未知名Android用户18 小时前
Android动态变化渐变背景
android
nono牛19 小时前
Gatekeeper 的精确定义
android
stevenzqzq20 小时前
android启动初始化和注入理解3
android
城东米粉儿1 天前
compose 状态提升 笔记
android
粤M温同学1 天前
Android 实现沉浸式状态栏
android
ljt27249606611 天前
Compose笔记(六十八)--MutableStateFlow
android·笔记·android jetpack