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

案例代码

相关推荐
火柴就是我1 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
砖厂小工8 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心8 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心8 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker11 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴11 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜1 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker1 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95271 天前
Andorid Google 登录接入文档
android
黄林晴1 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack