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

案例代码

相关推荐
一条上岸小咸鱼5 小时前
Kotlin 基本数据类型(一):Numbers
android·前端·kotlin
Huntto6 小时前
最小二乘法计算触摸事件速度
android·最小二乘法·触摸事件·速度估计
一笑的小酒馆6 小时前
Android中使用Compose实现各种样式Dialog
android
红橙Darren6 小时前
手写操作系统 - 编译链接与运行
android·ios·客户端
鹏多多.10 小时前
flutter-使用device_info_plus获取手机设备信息完整指南
android·前端·flutter·ios·数据分析·前端框架
来来走走14 小时前
Flutter开发 网络请求
android·flutter
独行soc21 小时前
2025年渗透测试面试题总结-18(题目+回答)
android·python·科技·面试·职场和发展·渗透测试
雨白1 天前
登录和授权:Cookie与Authorization Header机制详解
android
Frank_HarmonyOS1 天前
【Android -- 多线程】Handler 消息机制
android
一条上岸小咸鱼1 天前
Kotlin 基本数据类型(一):概述及分类
android·kotlin