SLaks 2013-06-19 05:13 采纳率: 0%
浏览 7697
已采纳

Android 自定义 ListView item 不能点击

我获得一个自定义的 ListView,然后使用不同的项目布局填充。问题是 OnItemClickListener 处理 ListView 只能捕捉 imageView 的点击事件,但是在其余的2个 textViews 上都不行。如何修改呢?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/Fourdp"
    android:layout_marginLeft="@dimen/Fourdp"
    android:layout_marginRight="@dimen/Fourdp"
    android:layout_marginTop="@dimen/Fourdp"
    android:gravity="left|center"
    android:paddingBottom="5px"
    android:paddingLeft="5px"
    android:paddingTop="5px" 
    android:descendantFocusability="blocksDescendants">

    <ImageView
        android:id="@+id/color"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/Fourdp"
        android:layout_marginLeft="@dimen/Fourdp"
        android:layout_marginRight="@dimen/Fourdp"
        android:layout_marginTop="@dimen/Fourdp"/>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:longClickable="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/task"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#336699" />
    </LinearLayout>

</LinearLayout>

我想在 ImageView 上设置 android:focusable="false" 和 android:clickable="false" ,但还是不能运行。

  • 写回答

1条回答

  • JaveZh 2013-06-19 06:22
    关注

    如果你只是想点击item就反应而不是针对每一个,你可以在item的根layout中加入:

    android:descendantFocusability=”blocksDescendant”
    

    如果你是想每个点击不同处理,直接用holder去找每个,然后设置onClick事件

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型