listview的item中含有button导致onitemclick事件失效的解决方法

来源:互联网 发布:孝义网络花店 编辑:程序博客网 时间:2024/05/16 00:58

在ListView子项目布局文件中的根控件中添加

android:descendantFocusability="blocksDescendants"

添加前:

<?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:orientation="vertical">    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="horizontal">

添加后:

<?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:descendantFocusability="blocksDescendants"    android:orientation="vertical">    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="horizontal">

按钮的点击事件写在getview里:
这里写图片描述

0 0