天天看點

ListView中CheckBox的擷取焦點沖突解決方法

本文借鑒自慕課網鴻洋老師《Android-打造萬能擴充卡》視訊講解:

http://www.imooc.com/video/7269

解決方法如下:

1. 布局檔案CheckBox的focusable設定為false

<CheckBox

android:focusable="false"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true" />

2. 布局最外層Layout設定descendantFocusability

<RelativeLayout ....

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:descendantFocusability="blocksDescendants" >

...

</RelativeLayout>