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

案例代码

相关推荐
苦学编程啊15 小时前
【2025Flutter 入门指南】Dart SDK 安装与 VS Code 环境配置-Windows
android·dart
yuanManGan21 小时前
走进Linux的世界:初识操作系统(Operator System)
android·linux·运维
叶羽西1 天前
Android15跟踪函数调用关系
android
消失的旧时光-19431 天前
webView 的canGoBack/goBack 回退栈
android·webview
SHEN_ZIYUAN1 天前
Flow 责任链模式图解
android
沐怡旸1 天前
【底层机制】LeakCanary深度解析:从对象监控到内存泄漏分析的完整技术体系
android·面试
又菜又爱coding1 天前
Android + Flutter打包出来的APK体积太大
android·flutter
LiuYaoheng1 天前
【Android】Drawable 基础
android·java
Jerry1 天前
构建 Compose 界面
android
Y多了个想法1 天前
Linux驱动开发与Android驱动开发
android·linux·驱动开发