相信很多像我一样的初学者在用listview时会遇到类似:item中如果有button的时候
这个item中button的点击事件与listview中item点击事件 的响应不能同时满足
稍微研究了一会 学习到一个解决方案:
1、在item的xml布局文件的 根布局标签中加入
android:descendantFocusability="blocksDescendants"
2、在button标签的属性中添加
android:focusable="false"(android:clickable="true"这句貌似可以不加)
tip: Don't forget to add the click event of button and the item click event of listview!
解决ListView与Item内Button点击事件冲突的方案

本文详细介绍了在使用ListView时遇到Item内Button点击事件与ListView自身点击事件响应冲突的问题,并提供了解决方案。通过在Item布局XML中设置android:descendantFocusability属性为blocksDescendants,并使Button的android:focusable属性为false,可以实现Button点击事件与ListView点击事件的合理分离。
2869

被折叠的 条评论
为什么被折叠?



