今天工作 遇到了 listview item中加入button 结果button能够触发点击事件 但是 item死活不触发 原来 button将item的事件给屏蔽了 需要在自己的视图文件中加入1个属性 仅仅一个属性就够了
<?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"
android:background="@drawable/listview_bg"
android:descendantFocusability="blocksDescendants"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<Button
android:id="@+id/recent_job_putaway"
android:layout_width="45dp"
android:layout_height="25dp"
android:textSize="13sp"
android:background="@drawable/soldout"
android:textColor="@color/salary_status_green"
android:text="下架" />
<Button
android:id="@+id/recent_job_soldout"
android:layout_width="45dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="@drawable/delete_jianzhi"
android:textColor="@color/salary_status_red"
android:textSize="13sp"
android:text="删除"/>
</RelativeLayout>
只要在item的布局文件中加入 android:descendantFocusability="blocksDescendants"这个属性 一切问题搞定 真是烦人啊 安卓的 事件传播机制