我有一个的ListView
是夸大的每一行包含一个复选框
和多个的TextView S中的在 RelativeLayout的
。问题是,我无法弄清楚如何从复选框后排传递的onclick事件。我想要实现这个行为:用户preSS的复选框,并在整个列表行获得pressed。我看到这种行为,如果我夸大的每一行 android.R.layout.simple_list_item_multiple_choice
,但我无法弄清楚如何做到这一点没有这个机器人的具体布局。
任何人都可以给我一个想法或方向?
下面是code:
列表视图:
< ListView控件 机器人:ID =@ + ID / include_sent_list_view 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 机器人:背景=@色/白 机器人:cacheColorHint =@色/白 机器人:layout_alignParentTop =真/>
和该膨胀的每一行的XML:
< RelativeLayout的 的xmlns:机器人=http://schemas.android.com/apk/res/android 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT><复选框 机器人:ID =@ + ID / checked_radio_button 机器人:layout_width =50dp 机器人:layout_height =FILL_PARENT 机器人:layout_alignParentLeft =真 机器人:可聚焦=假 /><的TextView 机器人:ID =@ + ID / account_number_text 机器人:layout_width =100dp 机器人:layout_height =FILL_PARENT 风格=@风格/ config_simple_small_text_view_style 机器人:paddingTop =15dp 机器人:layout_toRightOf =@ ID / checked_radio_button /><的TextView 机器人:ID =@ + ID / account_name_text 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 风格=@风格/ config_simple_small_text_view_style 机器人:paddingTop =15dp 机器人:layout_toRightOf =@ ID / account_number_text/>< / RelativeLayout的>
解决方案
复选框消耗重点用于列表项。您需要设置这个在您的布局文件:
<! - 必须使这不能成为焦点的,否则它消耗 - ><! - 意为列表项事件(即长preSS) - GT;<复选框 机器人:ID =@ + ID / item_entry_check 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_alignParentRight =真 机器人:layout_centerVertical =真 机器人:可聚焦=假 />
I have a ListView
that inflate for each row a xml that contain a CheckBox
and more TextView
s that are in a RelativeLayout
.
The problem is that I can't figure out how to pass onClick events from checkbox to back row.
I want to achieve this behavior: The user press the checkbox and the whole list row gets pressed. I saw this behavior if I inflate for each row android.R.layout.simple_list_item_multiple_choice
but I can't figure out how to do that without this android specific layout.
Can anybody give me an idea or direction?
Below is the code:
Listview :
<ListView
android:id="@+id/include_sent_list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:cacheColorHint="@color/white"
android:layout_alignParentTop="true"/>
And the xml that is inflated for each row:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox
android:id="@+id/checked_radio_button"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:focusable="false"
/>
<TextView
android:id="@+id/account_number_text"
android:layout_width="100dp"
android:layout_height="fill_parent"
style="@style/config_simple_small_text_view_style"
android:paddingTop="15dp"
android:layout_toRightOf="@id/checked_radio_button"
/>
<TextView
android:id="@+id/account_name_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/config_simple_small_text_view_style"
android:paddingTop="15dp"
android:layout_toRightOf="@id/account_number_text"/>
</RelativeLayout>
解决方案
The Checkbox consumes focus for the List item. You need to set this in your layout file:
<!-- Must make this non-focusable otherwise it consumes -->
<!-- events intended for the list item (i.e. long press) -->
<CheckBox
android:id="@+id/item_entry_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"
/>