gpt4 book ai didi

android - 带有复选框问题的 ListView

转载 作者:行者123 更新时间:2023-11-29 18:13:49 26 4
gpt4 key购买 nike

我有一个 ListView,它为每一行膨胀一个包含 CheckBox 的 xml 和 中的更多 TextView相对布局。问题是我不知道如何将 onClick 事件从复选框传递到后排。我想实现这种行为:用户按下复选框并按下整个列表行。如果我为每一行 android.R.layout.simple_list_item_multiple_choice 膨胀,我会看到这种行为,但如果没有这个 android 特定的布局,我无法弄清楚如何做到这一点。

任何人都可以给我一个想法或方向吗?

代码如下:

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"/>

以及为每一行扩充的 xml:

<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>

最佳答案

复选框占用列表项的焦点。您需要在您的布局文件中进行设置:

<!-- 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"
/>

关于android - 带有复选框问题的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9277735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com