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端“动画“】+ 实现补间动画和逐帧动画!!!
android·前端·android studio
这儿有一堆花1 小时前
打造你的 Android 图像编辑器:深入解析 PhotoEditor 开源库
android·开源
皮皮高2 小时前
itvbox绿豆影视tvbox手机版影视APP源码分享搭建教程
android·前端·后端·开源·tv
EnzoRay2 小时前
MotionEvent
android
玲小珑3 小时前
Auto.js 入门指南(七)定时任务调度
android·前端
墨狂之逸才3 小时前
adb常用命令调试
android
YoungForYou3 小时前
Android端部署NCNN
android
移动开发者1号4 小时前
Jetpack Compose瀑布流实现方案
android·kotlin
移动开发者1号4 小时前
Android LinearLayout、FrameLayout、RelativeLayout、ConstraintLayout大混战
android·kotlin
移动开发者1号4 小时前
ListView与RecyclerView区别总结
android·kotlin