知道处于何种原因,如题所述。
解决方法:1. 将RelativeLayout作为ListView的父控件。2.用baseAdapter作为ListView的适配器。
其中使用了各种使ListView的Item获得焦点的方法都无济于事,包括如下:
1.listView.setItemsCanFocus(true); //设置item项的子控件能够获得焦点(默认为false,即默认item项的子空间是不能获得焦点的)
2.android:descendantFocusability=”blocksDescendants”
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.
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
这其实是解决Item作为一个ViewGroup时,时Item中的子控件获取到焦点的做法,而不是使ListView中的Item获得焦点的方法。3.**解决方法:**
1. 在xml中设置Button的android:focusable="false", 这样Button就不会去抢夺焦点了.//防止item中的ViewGroup(Item中包含了一个ViewGroup)中的子控件抢焦点
2. 在getView()中设置Button不去获取焦点, btn.setFocusable(false).//与上面解决一样
3. 设置item的根布局的配置android:descendantFocusability="blocksDescendant"//优先Item抢焦点(其实Item应该算是一个比用户设置的的ViewGroup更外层的VIewGroup)