1。android:descendantFocusability
一般情况下为了使用ListView的onItemClick,onItemLongClick方法,屏蔽子控件对焦点的获取,所以应将该值由
blocksDescendants 改为 afterDescendants
ps:
android:descendantFocusability
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
Constant Value Description
beforeDescendants 0 The ViewGroup will get focus before any of its descendants.
afterDescendants 1 The ViewGroup will get focus only if none of its descendants want it.
blocksDescendants 2 The ViewGroup will block its descendants from receiving focus
2.在×××Adapter类的getView中调用子控件的setFocusable属性,及实现相应的Click函数(由于子控件获取焦点后,listview的onItemClick,onItemLongClick不再会被调用,
所以也一并实现,对于onItemLongClick函数,注意要返回TRUE,否则会发现该函数相应的代码会走两遍,估计是ListView的onItemLongClick被触发,有待深究)。
3.调用ListView的setItemsCanFocus(TRUE)函数
本文介绍如何通过设置ListView的android:descendantFocusability属性来避免子控件抢夺焦点,确保ListView的点击事件正常工作。同时提供了调整子控件setFocusable属性的方法,并实现了相应的Click函数。
1654

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



