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

案例代码

相关推荐
事圆则缓13 分钟前
Kotlin 高阶工程化与 Android 深入实践
android·开发语言·kotlin
zhangphil17 分钟前
AI大模型生成maxTokens 与上下文context
android·llama
淡淡的香烟20 分钟前
Androidiot开发之猫脸识别
android·物联网
2501_9151063231 分钟前
iOS数据采集技术详解:从性能监控到崩溃分析的全链路实践
android·ios·小程序·https·uni-app·iphone·webview
天空之城--9 小时前
Android Koin 完全指南:从原理到实践
android
zhangphil10 小时前
Android main thread主线程Choreographer doFrame发生FullSuspendCheck
android
TimeFine14 小时前
智能眼镜开发:获取真实的音频路由
android
pengyu14 小时前
【Kotlin 协程修仙录 · 渡劫境 · 中阶】 | 造化神兵:自定义 CoroutineDispatcher 与调度器的终极定制
android·kotlin
pengyu15 小时前
【Kotlin 协程修仙录 · 渡劫境 · 初阶】 | 飞升雷劫:CPS 变换与挂起函数字节码终极透视
android·kotlin
TimeFine15 小时前
智能眼镜开发:眼镜Touch后收音与触发播放系统音乐的矛盾处理
android