ListView 和 其它能触发点击事件的widget无法一起正常工作的原因是加入其它widget后,ListView的itemclick事件将无法触发,被其它widget的click事件屏蔽。
res/layout/lvitem.xml
注意:
在<RelativeLayout>中
android:descendantFocusability="blocksDescendants"
和<ImageButton>中
android:focusable="false"
这两项的设置很关键,如果不设置,将导致ListView的ItemClick事件将无法触发,该事件被ImageButton的click事件屏蔽了。
如图:

本文探讨了在Android开发中,ListView与其他Widget(如ImageButton)共存时可能出现的点击事件冲突问题。详细介绍了如何通过设置RelativeLayout的descendantFocusability属性为blocksDescendants及ImageButton的focusable属性为false来解决此问题。

363

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



