我想建立一个列表视图,每行都有一个带有图像和textview的复选框,我几乎成功了,但是当我把复选框我不能按下list_row,我的意思是在我把复选框之前我可以点击行和它像我在我的风格中一样悬停,但是当我点击list_row后我放了复选框它没有悬停并且onitemclick不起作用,为什么?
这是我每个list_row的xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/restaurant_list_item_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:background="@drawable/restaurant_list_item_image_bg"
android:padding="3dip" >
<ImageView
android:id="@+id/restaurant_multi_select_list_item_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/rihanna" />
</LinearLayout>
<TextView
android:id="@+id/restaurant_multi_select_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<!-- Rightend check box -->
<CheckBox
android:id="@+id/restaurant_multi_select_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:checked="false"
/>
</RelativeLayout>
答案 0 :(得分:2)
添加可聚焦元素(如CheckBox或Button)会禁用单击整个列表项的功能,并且必须禁用它们的可聚焦性。
在xml的复选框属性中添加以下内容,然后尝试
android:focusable="false"
android:focusableInTouchMode="false"
希望这有帮助!!!
答案 1 :(得分:1)
是的,因为复选框存在使视图无法点击。您需要实现您正在使用的ImageView和TextView的onClicklistenrs,并在列表行上单击所需的相同代码点击
设置焦点仅对触摸有帮助,但也会实现复选框点击