使用复选框不可点击列表项 [英] List item with CheckBox not clickable
问题描述
我有一个包含一个复选框列表项,我希望能够点击复选框,并在列表项本身。遗憾的是,似乎有某种两者之间的冲突,我只能请单击该项目时,我注释掉的复选框。好像我记得有一个方法来解决这个问题,但我不能找到它的时刻。谢谢
编辑:这是一个ListFragment,所以没有必要调用setOnItemClickListener
。确定,这里的XML列表项。问题是复选框,但我想还不如复制的一切。
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / list_item_survey
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
风格=@风格/ SimpleListItem>
<的TextView
机器人:ID =@ + ID / survey_title
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
风格=@风格/ ListItemTitle/>
<的TextView
机器人:ID =@ + ID / survey_date
机器人:layout_below =@ ID / survey_title
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
风格=@风格/ ListItemSubtitle/>
<的TextView
机器人:ID =@ + ID / survey_completed
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_below =@ ID / survey_title
机器人:文字颜色=@色/ accent_1
机器人:文本=@字符串/ survey_completed
风格=@风格/ ListItemSubtitle/>
<复选框
机器人:ID =@ + ID / survey_did_not_attend
机器人:layout_below =@ ID / survey_date
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/ survey_did_not_attend
机器人:可聚焦=假
风格=@风格/ ListItemSubtitle/>
< / RelativeLayout的>
如前所述这里一>和<一href="http://$c$c.google.com/p/android/issues/detail?id=3414&can=1&q=listview&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars">here,这可以是一个已知的问题或作品设计的。如果你有一个列表项的任何点击或可成为焦点的项目,列表项目本身不能点击。罗曼盖伊说这是工作的目的是支持轨迹球/ DPAD导航。
I have a list item which contains a CheckBox, and I want to be able to click on the CheckBox and on the list item itself. Unfortunately, there seems to be some sort of conflict between the two, as I can only click on the item when I comment out the CheckBox. It seems like I recall there was a way to fix this, but I can't find it at the moment. Thanks
EDIT: This is with a ListFragment, so there's no need to call setOnItemClickListener.
OK, here's the XML for the list item. The problem is the CheckBox, but I figured might as well copy everything.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item_survey"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/SimpleListItem">
<TextView
android:id="@+id/survey_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/ListItemTitle" />
<TextView
android:id="@+id/survey_date"
android:layout_below="@id/survey_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/ListItemSubtitle" />
<TextView
android:id="@+id/survey_completed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/survey_title"
android:textColor="@color/accent_1"
android:text="@string/survey_completed"
style="@style/ListItemSubtitle" />
<CheckBox
android:id="@+id/survey_did_not_attend"
android:layout_below="@id/survey_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/survey_did_not_attend"
android:focusable="false"
style="@style/ListItemSubtitle" />
</RelativeLayout>
As described here and here, this is either a known problem or works as designed. If you have any clickable or focusable items in a list item, the list item itself cannot be clickable. Romain Guy says "This is working as intended to support trackball/dpad navigation."
这篇关于使用复选框不可点击列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!