Android List 自定义 Item 点击无效
2013-09-27 18:24 richardzhaoxb 阅读(538) 评论(0) 编辑 收藏 举报List Item 自定义 layout 如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" > 5 6 <CheckBox 7 android:id="@+id/crime_list_item_solvedCheckBox" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content" 10 android:gravity="center" 11 android:layout_alignParentRight="true" 12 android:enabled="false" 14 android:padding="4dp"/> 15 16 <TextView 17 android:id="@+id/crime_list_item_titleTextView" 18 android:layout_width="match_parent" 19 android:layout_height="wrap_content" 20 android:layout_toLeftOf="@id/crime_list_item_solvedCheckBox" 21 android:textStyle="bold" 22 android:paddingLeft="4dp" 23 android:paddingRight="4dp" 24 android:text="Crime title"/> 25 26 <TextView 27 android:id="@+id/crime_list_itme_dateTextView" 28 android:layout_width="match_parent" 29 android:layout_height="wrap_content" 30 android:layout_below="@id/crime_list_item_titleTextView" 31 android:layout_toLeftOf="@id/crime_list_item_solvedCheckBox" 32 android:paddingLeft="4dp" 33 android:paddingRight="4dp" 34 android:paddingTop="4dp" 35 android:text="Crime Date" /> 36 37 </RelativeLayout>
显示如下:
但是 这个 item 死活不能点击。
最终找到是 check box 不可用导致的问题, 因为是 只读的,就设置了 enable = false, 但是还要给 CheckBox 加一个属性: android:focusable="false", 否则这个 list item 都不能被点击。 晕死。