android ListView Item和CheckBox、Button点击事件冲突的问题

在Item的根目录上设置属性:

//表示锁定子View的焦点,不让Layout下的子View获取
android:descendantFocusability="blocksDescendants"

CheckBox和Button设置属性:

//三个属性都需要设置为false
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

完整的布局文件示例:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:orientation="horizontal">
        <CheckBox
            android:id="@+id/box"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:visibility="gone"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:clickable="false"
            android:layout_marginLeft="8dp"
            android:button="@drawable/check_box_background"
            android:gravity="center_vertical" />

        <TextView
            android:id="@+id/text_name"
            android:layout_width="wrap_content"
            android:paddingRight="5dp"
            android:layout_weight="0.1"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:layout_marginLeft="20dp"
            android:text="点名"
            android:textColor="@color/gray2"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/text_workinfo"
            android:layout_width="0dp"
            android:layout_weight="0.99"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:paddingLeft="5dp"
            android:minHeight="45dp"
            android:layout_marginRight="5dp"
            android:text="0.0"
            android:textColor="@color/green"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/text_edit"
            android:layout_width="0dp"
            android:layout_weight="0.4"
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_marginRight="5dp"
            android:text="编辑"
            android:textColor="@color/black"
            android:background="@drawable/border_line_corner_blue"
            android:textSize="14sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:visibility="visible"
        android:background="@color/gray" />
</LinearLayout>





转载于:https://my.oschina.net/u/266531/blog/547442

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值