【问题标题】:MvxListViews with checkboxes inside the ItemsSource are not selectable在 ItemsSource 中带有复选框的 MvxListViews 不可选择
【发布时间】:2014-04-16 00:39:29
【问题描述】:

我有一个 MvxListView,其中显示了一些食谱卡片。当用户单击卡片时,他们应该被带到详细信息屏幕。我遇到的问题是,当单元格中有 CheckBox(绑定或未绑定)时,整个单元格会忽略单击事件。

我的 MvxListView 是通过以下方式创建的:

    <MvxListView
    android:layout_margin="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    local:MvxBind="ItemsSource Recipes; ItemClick ShowRecipeDetailCommand"
    local:MvxItemTemplate="@layout/use_recipe_list_item"
    android:divider="@android:color/transparent"
    android:dividerHeight="10dp" />

列表项是通过以下方式创建的:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:local="http://schemas.android.com/apk/res-auto"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:background="@color/use_detail_recipe_background"
              android:padding="10dp">
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Title"
                android:id="@+id/tvTitle"
                android:textSize="24sp"
                local:MvxBind="Text Title"
                android:layout_weight="1"
                android:layout_toLeftOf="@+id/cbFavorite"
                android:textColor="@color/use_detail_recipe_title_text" />
    <!--    <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/cbFavorite"
                android:layout_alignParentTop="true"
                android:layout_alignParentRight="true"
                android:checked="false"
                android:layout_weight="0" />-->
        <View
                android:id="@+id/vDivider1"
                android:layout_width="fill_parent"
                android:layout_height="2dp"
                android:background="#000000"
                android:layout_below="@+id/tvTitle" />
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Content"
                android:id="@+id/tvContent"
                android:singleLine="false"
                android:layout_below="@+id/vDivider1"
                local:MvxBind="Text Content"
                android:textColor="@color/use_detail_recipe_content_text"
                android:maxLines="4"/>
    </RelativeLayout>

如果未注释掉该复选框,则此方法有效。我该如何解决这个问题?是否可以在项目中单击我的基本RelativeLayout添加命令?

【问题讨论】:

标签: mvvmcross


【解决方案1】:

感谢斯图尔特的提示。这确实不是 MvvmCross 问题,而是一般的 Android 问题。

解决方案是为每个可点击项添加以下内容:

android:focusable="false"
android:focusableInTouchMode="false"

这条评论让我走上了正轨https://stackoverflow.com/a/15859831/83301

【讨论】:

    猜你喜欢
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2012-05-27
    • 1970-01-01
    相关资源
    最近更新 更多