您的位置:首页 > 移动开发 > Android开发

Android ListView 中子控件无法获取焦点的解决方法(主要针对键盘操作)

2012-10-13 16:41 886 查看
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)函数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐