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

案例代码

相关推荐
法欧特斯卡雷特几秒前
Kotlin Sequence 真的如此不堪吗?
android·后端·编程语言
pengyu3 分钟前
系统化掌握Flutter开发之GestureDetector(一):筑基之旅
android·flutter·dart
帅次11 分钟前
Flutter Widget 体系结构解析
android·flutter·ios·小程序·xcode·web app·dalvik
罗狮粉 992 小时前
Mysql主从复制和Mysql高可用以及负载均衡配置
android·mysql·负载均衡
@Dai2 小时前
【Python】为什么要写__init__.py
android·java·python
缘来的精彩3 小时前
Android JNI性能优化与字符串加载实践
android·性能优化·jni·androidndk
weixin_4607838711 小时前
Flutter解决TabBar顶部页面切换导致页面重载问题
android·javascript·flutter
qhs157312 小时前
Kotlin字符串操作在Android开发中的应用示例
android·开发语言·kotlin
网络安全(king)14 小时前
Android networkSecurityConfig 代码配置
android
LuXi_foryou14 小时前
【2025深夜随笔】简单认识一下Android Studio
android·ide·android studio