Android中ListView的条目中有button时,item的点击事件失效

Android中ListView的条目中有button时,item的点击事件失效。

这个问题我总结了3点:

1、button的点击事件要写在自定义适配器中。

2、ListView条目点击事件要写在Activity中。

3、button的属性中必须要写 android:focusable="false"。

4、在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了,至此listview点击的灵异事件告一段落。心得:遇到不会不懂的地方除了网上查询资料之外,也可以多多去尝试每种属性的作用,多阅读官方文档(我始终觉得还是读原文的比翻译的理解的会更好)。

写好以上三点,则listview的条目有点击事件,button中也有点击事件,一切正常。

猜你喜欢

转载自blog.csdn.net/hubianyu/article/details/78919519