父ListView嵌套子ListView时点击事件没有响应

转发请备注出处:http://www.cnblogs.com/LT5505/p/5972999.html 

问题:

在ListView中嵌套ListView之后,子ListView会把父ListView的焦点吃掉,导致父ListView的OnItemClickListener不起作用,这就要屏蔽掉子ListView的焦点。

解决方法:

一、设置父ListView的最外层布局中加入:android:descendantFocusability="blocksDescendants"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    >
<ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        ></ListView>
</LinearLayout>

 

二、取消子ListView控件的焦点

listview.setFocusable(false);
listview.setClickable(false);

但是设置到了这里还是没有效果,然后我干脆把子ListView所有的事件和焦点都屏蔽掉,添加代码:

listview.setPressed(false);
listview.setEnabled(false);

全部设置完后父ListView的OnItemClickListener终于响应了,捣鼓了一下,记下来,下次就知道了要全部屏蔽才能有效果。

转载于:https://www.cnblogs.com/LT5505/p/5972999.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值