Android的ListView中每一行都有一个复选框 [英] android listview each row has a checkbox
问题描述
我想建立一个列表视图,每行有图像和TextView的一个复选框,我几乎做到了,但是当我把复选框我不能preSS的list_row,我的意思是之前我把我的复选框可以单击该行并将其悬停正如我在我的风格做了,但是以后我把复选框,当我在list_row点击它没有悬停和onitemclick不起作用,为什么?
这是我的每个list_row的XML
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@绘制/ restaurant_list_item_selector
机器人:方向=横向
机器人:填充=5dip> <! - ListRow左SIED缩略图 - > <的LinearLayout
机器人:ID =@ + ID /缩略图
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_marginRight =5dip
机器人:背景=@绘制/ restaurant_list_item_image_bg
机器人:填充=3dip> < ImageView的
机器人:ID =@ + ID / restaurant_multi_select_list_item_image
机器人:layout_width =50dip
机器人:layout_height =50dip
机器人:SRC =@绘制/蕾哈娜/>
< / LinearLayout中> <的TextView
机器人:ID =@ + ID / restaurant_multi_select_title
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignTop =@ + ID /缩略图
机器人:layout_toRightOf =@ + ID /缩略图
机器人:文字颜色=#040404
机器人:TEXTSIZE =15dip
机器人:文字样式=大胆
机器人:字体=SANS/> <! - Rightend复选框 - > <复选框
机器人:ID =@ + ID / restaurant_multi_select_checkBox
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_centerVertical =真
安卓:检查=假
/>< / RelativeLayout的>
添加可聚焦元素(如复选框或按钮)禁用点击整个列表项的能力和可聚焦已被禁用。
添加以下你的复选框中的XML属性,然后尝试
机器人:可聚焦=假
机器人:focusableInTouchMode =假
希望这有助于!
i want to build an listview and each row has a checkbox with image and textview, i almost made it, but when i put the checkbox i can't press the list_row, i mean before i put the checkbox i can click the row and it hover as i did in my style, but after i put the checkbox when i click on the list_row it didn't hover and the onitemclick doesn't work, why ?
this is the xml of my each list_row
<?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>
Adding focusable elements (like CheckBox or Button) disables the ability to click the overall list item and their focusability has to be disabled.
Add the following in your checkbox attributes in the xml and then try
android:focusable="false"
android:focusableInTouchMode="false"
Hope this helps!!!
这篇关于Android的ListView中每一行都有一个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!