Android开发UI之ListView中的Button点击设置

在ListView的Item中,如果有Button控件,那么要实现Button和Item点击都有响应,可以将Item的Layout中Button的focusable属性设为false,然后设置layout的属性android:descendantFocusability="blocksDescendants"。

代码如下:

 1 <?xml version="1.0" encoding="utf-8"?>  
 2 <LinearLayout  
 3   xmlns:android="http://schemas.android.com/apk/res/android"  
 4   android:layout_width="fill_parent"  
 5   android:layout_height="wrap_content"  
 6   android:descendantFocusability="blocksDescendants">  
 7   <TextView  
 8     android:layout_width="fill_parent"  
 9     android:layout_height="wrap_content"/>  
10   <Button  
11     android:layout_width="wrap_content"  
12     android:layout_height="wrap_content"  
13     android:focusable="false"/>  
14 </LinearLayout>  
原文地址:https://www.cnblogs.com/liyiran/p/4634538.html