Question

I have an MvxListView that I'm showing some recipe cards in. When the user clicks a card they should be taken to a detail screen. The problem I'm running into is that when there is a CheckBox (bound or unbound) in the cell, the entire cell ignores the click event.

My MvxListView is created with:

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

The List item is created with:

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

If the checkbox isn't commented out, this works. How can I work around this? Would it be possible to add a command to the click on my base RelativeLayout in the item?

Was it helpful?

Solution

Thanks for the tip Stuart. This is indeed not a MvvmCross issue but rather a general Android issue.

The solution was to add the following to each clickable item:

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

This comment got me on the right track https://stackoverflow.com/a/15859831/83301.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top