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

案例代码

相关推荐
LionelRay11 分钟前
Thinking in Compose
android
用户69371750013842 小时前
Google 推 AppFunctions:手机上的 AI 终于能自己干活了
android·前端·人工智能
用户69371750013842 小时前
AI让编码变简单,真正拉开差距的是UI设计和产品思考
android·前端·人工智能
zh_xuan2 小时前
Android Jetpack DataStore存储数据
android·android jetpack·datastore
程序员陆业聪2 小时前
在 Android 上跑大模型,你选错引擎了吗?
android
studyForMokey4 小时前
【Android面试】View绘制流程专题
android·面试·职场和发展
jjinl6 小时前
Android 资源说明
android
恋猫de小郭8 小时前
Swift 6.3 正式发布支持 Android ,它能在跨平台发挥什么优势?
android·前端·flutter
一只会跑会跳会发疯的猴子8 小时前
php操作ssl,亲测可用
android·php·ssl
程序员码歌9 小时前
火爆了,一个Skill搞定AI热点自动化:RSS 聚合 + AI 筛选 + 公众号 + 邮件全流程
android·前端·ai编程