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

案例代码

相关推荐
好的佩奇37 分钟前
蓝牙之 GATT 数据模型
android·flutter·蓝牙
Android小码家1 小时前
Systemui和Launcher是如何无限重启
android·framework
GY-936 小时前
【Android】WorkManager
android
fatiaozhang95278 小时前
开心电视助手极速版-版本9.6-新增安卓平台版本
android·开心电视助手极速版·版本9.6
urkay-9 小时前
Android 线程池工具类与监控
android·java·性能优化
StarsGreen9 小时前
Android 12 添加 v4l2_codec 服务详细流程
android
FungLeo10 小时前
FengCMS · PHP+MySQL升级实录 · 存量站升级方法论:备份 → 副本验收→migrate.php→ 停写切换
android·mysql·php·工程实践·fengcms
booboosui1 天前
清单 40 件是硬上限:过期的活挂了 48 小时才被打标记
android