當ListView的Item中有Button的時候,會出現Button可以點擊,但是Item不可以點擊的問題。
解決辦法如下:
在ListView的每一個Item佈局文件的最外層佈局加上如下代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability= "blocksDescendants"
android:orientation="horizontal">
其次就是讓Item佈局中按鈕獲取不到焦點,但是要保證它可以響應點擊事件,在按鈕的佈局代碼中加上如下代碼:
<Button
android:id="@+id/bt_receive_file"
android:layout_width="60dip"
android:layout_height="40dip"
android:layout_marginLeft="5dip"
android:textSize="17sp"
android:focusable = "false"
android:text="接收"/>