Android_listview点击失效

listview点击失效,原因可能是item布局中存在Button,该Button夺取了焦点。

解决办法:

1,在xml布局中,为Button添加android:focusable="false"

2,在item布局的根据点添加android:descendantFocusability="blocksDescendants"

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会覆盖子类控件而直接获得焦点
3,不要用Button,而是TextView代替,至于点击效果,再另写。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。