相信很多朋友设置了有Button的ListView之后,监听listview的item不生效了
这里有三种解决办法
1、在listView的item根布局中设置属性
android:descendantFocusability="blocksDescendants"
2、设置listView的item中的Button属性
android:focusable="false"
android:focusableInTouchMode="false"
3、直接在adapter中对对应的view进行监听
这三种办法都可以解决这个问题
那么为什么会出现这个现象呢?
查看源码AbsListView中:
可以看出只有在child.hasFocusable()为false的情况下才会触发click事件,那么默认情况下Button是有focus的会导致他的parent也有focus,所以就无法触发click事件
private void onTouchUp(MotionEvent ev) {
switch (mTouchMode) {
.