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>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C#中,要为ListView控件中的CheckBox添加事件,可以使用ListView的ItemCheck事件。该事件会在用户勾选或取消勾选一个项的CheckBox时触发。 以下是一个示例代码,演示如何在ListView的每个项中添加CheckBox,并在用户勾选或取消勾选时触发事件: ```csharp private void Form1_Load(object sender, EventArgs e) { // 添加ListView的列头 listView1.Columns.Add("Name", 100); listView1.Columns.Add("Age", 50); listView1.Columns.Add("Gender", 50); // 添加ListView的项 ListViewItem item1 = new ListViewItem("Tom"); item1.SubItems.Add("18"); item1.SubItems.Add("Male"); item1.Checked = true; listView1.Items.Add(item1); ListViewItem item2 = new ListViewItem("Jerry"); item2.SubItems.Add("20"); item2.SubItems.Add("Female"); item2.Checked = false; listView1.Items.Add(item2); // 添加ItemCheck事件处理程序 listView1.ItemCheck += new ItemCheckEventHandler(listView1_ItemCheck); } private void listView1_ItemCheck(object sender, ItemCheckEventArgs e) { // 获取被点击的项 ListViewItem item = listView1.Items[e.Index]; if (e.NewValue == CheckState.Checked) { // 用户勾选该项的CheckBox MessageBox.Show("用户勾选了:" + item.SubItems[0].Text); } else if (e.NewValue == CheckState.Unchecked) { // 用户取消勾选该项的CheckBox MessageBox.Show("用户取消勾选了:" + item.SubItems[0].Text); } } ``` 在上述代码中,我们首先在ListView的每个项中添加了一个CheckBox,并设置了每个CheckBox的初始勾选状态。然后,我们为ListView的ItemCheck事件添加了一个处理程序,以便在用户勾选或取消勾选一个项的CheckBox时触发相应的事件处理逻辑。在事件处理程序中,我们可以通过e.Index获取到被点击的项,进而获取该项的各个子项的内容(例如,第一个子项即为该项的名称)。根据e.NewValue属性的值,我们可以判断出用户是勾选了该项的CheckBox还是取消了勾选。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值