【发布时间】:2015-01-09 16:57:00
【问题描述】:
我在 MvxListView 上有以下绑定
<Mvx.MvxListView
android:id="@+id/listGroups"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_below="@+id/layoutGroupPadder"
android:dividerHeight="7dp"
android:divider="@drawable/list_divider"
local:MvxItemTemplate="@layout/list_group"
local:MvxBind="ItemsSource AvailableGroups; ItemClick GroupSelectedCommand" />
MvxItemTemplate如下
<?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/xxxx.xxxx"
android:orientation="horizontal"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="63dp">
<TextView
android:id="@+id/groupsGroupName"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="18dp"
android:gravity="center"
android:layout_margin="7dp"
android:textColor="@color/verydarknavy"
local:MvxBind="Text Name" />
<RelativeLayout
android:id="@+id/layoutGroupGroupCount"
android:orientation="horizontal"
android:layout_width="90dp"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
<TextView
android:id="@+id/groupsSubGroupCount"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:textSize="16dp"
android:gravity="center"
android:layout_margin="7dp"
android:textColor="@color/hblue"
android:layout_toLeftOf="@+id/imageArrowGrp"
local:MvxBind="Text SubGroupCount" />
<ImageView
android:src="@drawable/YellowArrowRight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="7dp"
android:layout_alignParentRight="true"
android:id="@+id/imageArrowGrp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutGroupItemCount"
android:orientation="horizontal"
android:layout_width="90dp"
android:layout_height="fill_parent"
android:layout_marginRight="14dp"
android:layout_alignParentRight="true"
android:fitsSystemWindows="false">
<TextView
android:id="@+id/groupsVehicleCount"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:textSize="16dp"
android:gravity="center"
android:layout_margin="7dp"
android:textColor="@color/hblue"
android:layout_toLeftOf="@+id/imageArrowItem"
local:MvxBind="Text VehicleCount" />
<ImageView
android:src="@drawable/YellowArrowRight"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_margin="7dp"
android:id="@+id/imageArrowItem" />
</RelativeLayout>
</RelativeLayout>
当 ItemClick 发生时 GroupSelectedCommand 正确触发:)
但是,我想根据用户在项目中触摸的位置触发 2 个不同的命令。我需要区分哪些 TexViews 已被触摸(SubGroupCount 或 VehicleCount)
我尝试将 MvxListView 中的绑定更改为
local:MvxBind="ItemsSource AvailableGroups" />
并将与 MvxItemTemplate 的绑定更改为
local:MvxBind="Text SubGroupCount; ItemClick GroupSelectedCommand " />
和
local:MvxBind="Text VehicleCount; ItemClick ItemSelectedCommand " />
我为命令 ItemSelectedCommand 创建了必要的处理。
不幸的是它没有触发任何一个命令。
是否可以从一个模板触发单独的命令,如果可以,如何将它们绑定到 MvxItemTemplate 中的不同控件?
【问题讨论】: