开发者社区> 问答> 正文

如何在ListView子条目中获取部分组件点击事件?

1、我希望在ListView的子条目中获部分组件的点击事件。
这是一个仿微信的项目,我希望当且仅当点击左边按钮、头像、文本框的情况下触发onitemclick方法。错误效果 如下。
screenshot
2、ListView的XML代码:

<ListView android:id="@+id/lv_id" android:layout_width="match_parent"
        android:layout_height="match_parent" android:layout_below="@id/et_search_id"
        android:descendantFocusability="blocksDescendants"/>

子条目的XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <TextView android:id="@+id/first_name_id" android:layout_width="wrap_content"
        android:layout_margin="6dp"    android:clickable="false"
        android:layout_height="wrap_content" android:textSize="@dimen/text_size_xs"/>
    <TextView android:id="@+id/name_id" android:layout_width="match_parent"
        android:layout_height="60dp" android:gravity="center_vertical"
        android:paddingStart="100dp" android:layout_below="@id/first_name_id"
        android:paddingEnd="0dp" android:background="@drawable/d_bg_item"/>
    <com.wuxianedu.wechat.widget.RoundImageView android:id="@+id/head_round_id" 
        android:layout_width="50dp" android:layout_alignTop="@id/name_id"
        android:layout_height="50dp" android:layout_alignBottom="@id/name_id"
        android:contentDescription="@string/load_fail"
        android:src="@drawable/head_nor" android:layout_marginTop="5dp"
        android:layout_marginStart="40dp" android:layout_marginBottom="5dp"/>
    <CheckBox android:id="@+id/cb_id" android:layout_width="30dp" 
        android:layout_height="30dp" android:layout_margin="6dp"
        android:layout_alignTop="@id/name_id" android:layout_alignBottom="@id/name_id"
        android:clickable="false" android:focusable="false"
        android:focusableInTouchMode="false" android:button="@drawable/d_bg_but_jy"/>
</RelativeLayout>

展开
收起
蛮大人123 2016-03-11 15:31:05 2772 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    checkbox.setOnClickListener(new MyListener());
    imageview.setOnClickListener(new MyListener());
    textview.setOnClickListener(new MyListener());

    自己写一个 MyListener 继承ClickListener... 做统一事件处理。完事。
    不推荐这么做,推荐这三个要接收点击事件的控件外包裹一层View,用View来接收点击事件。这样点击操作失误率会小一些以上手打伪代码.

    2019-07-17 18:59:23
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载