listview和checkbox点击事件冲突解决

本文介绍了一种解决ListView中Checkbox焦点冲突的方法,在父布局中设置android:descendantFocusability=blocksDescendants属性,使得ListView和Checkbox都能正常响应触摸事件。

在itemlist里面的父布局加上:
 android:descendantFocusability="blocksDescendants"(listview和checkbox事件都可以响应)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/y23"
    android:layout_marginLeft="@dimen/x23"
    android:layout_marginRight="@dimen/x23"
    android:layout_marginTop="@dimen/y23"
    android:background="@mipmap/list_paijian_yiwancheng_chang"
    android:descendantFocusability="blocksDescendants"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/cap_position"
        style="@style/text_28_white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/x68"
        android:text="1" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/cl_click_list_entity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/x114">

        <TextView
            android:id="@+id/cpa_waybill"
            style="@style/text_28_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/task"
            android:textColor="#aaffffff"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/cpa_waybill_value"
            style="@style/text_28_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/x23"
            android:text="0816196731-193855"
            app:layout_constraintLeft_toRightOf="@+id/cpa_waybill"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/cpa_weight"
            style="@style/text_28_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/y12"
            android:text="@string/department"
            android:textColor="#aaffffff"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cpa_waybill" />

        <TextView
            android:id="@+id/cpa_weight_value"
            style="@style/text_28_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/x23"
            android:layout_marginTop="@dimen/y12"
            android:text="@string/fake_business_depart"
            app:layout_constraintLeft_toRightOf="@+id/cpa_weight"
            app:layout_constraintTop_toBottomOf="@+id/cpa_waybill" />

        <TextView
            android:id="@+id/cpa_volume"
            style="@style/text_28_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/y12"
            android:text="@string/active"
            android:textColor="#aaffffff"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cpa_weight" />

        <TextView
            android:id="@+id/cpa_volume_value"
            style="@style/text_28_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/x23"
            android:layout_marginTop="@dimen/y12"
            android:text="@string/fake_votes"
            app:layout_constraintLeft_toRightOf="@+id/cpa_volume"
            app:layout_constraintTop_toBottomOf="@+id/cpa_weight_value" />

        <CheckBox
            android:id="@+id/is_check"
            android:layout_width="@dimen/x69"
            android:layout_height="@dimen/y69"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="@dimen/x75"
            android:layout_marginTop="8dp"
            android:background="@drawable/select_radio_bg"
            android:button="@null"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@id/cpa_weight_value"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.529" />
    </android.support.constraint.ConstraintLayout>

</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值