具有CheckBox的列表项无法单击

Sha*_*zon 22 android listview

我有一个包含CheckBox的列表项,我希望能够单击CheckBox和列表项本身.不幸的是,两者之间似乎存在某种冲突,因为我只能在注释掉CheckBox时单击该项.我好像记得有办法解决这个问题,但目前我找不到它.谢谢

编辑:这是一个ListFragment,所以没有必要调用setOnItemClickListener.

好的,这是列表项的XML.问题是CheckBox,但我想也可以复制一切.

<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>
Run Code Online (Sandbox Code Playgroud)

Sun*_*nil 28

你需要将它添加到自定义适配器xml文件android:descendantFocusability ="blocksDescendants"

  • 适配器xml文件有点令人困惑,它是项目xml文件 (4认同)

sar*_*mar 23

将其插入到项行 xml文件的根元素中

android:descendantFocusability="blocksDescendants"
Run Code Online (Sandbox Code Playgroud)


Sha*_*zon 8

如此此处所述,这是已知问题或按设计工作.如果列表项中有任何可点击或可聚焦的项目,则列表项本身不可单击.Romain Guy 说: "这是为了支持轨迹球/ dpad导航."


Kev*_*OUX 6

这对我有用

<CheckBox
...                
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false" />
Run Code Online (Sandbox Code Playgroud)