MvvmCross MvxListView和MvxItemTemplate。如何正确显示表格?

时间:2015-03-03 02:51:01

标签: c# android xamarin mvvmcross

我正在尝试使用MvvmCross创建数据输入表。这就是我所拥有的:

ShipmentView.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@style/InputEditText"
        local:MvxBind="Text Shipment.Shipper" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@style/InputEditText"
        local:MvxBind="Text Shipment.OrgAddress" />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@style/InputEditText"
        local:MvxBind="Text Shipment.OrgEmail" />
    <Mvx.MvxListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        local:MvxBind="ItemsSource ShipmentInventory.Items"
        local:MvxItemTemplate="@layout/inventoryitemdetailview" />
</LinearLayout>

ShipmentInventory.Items是ShipmentInventoryItem的ObservableCollection。我的项目的模板如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <EditText
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      style="@style/InputEditText"
      local:MvxBind="Text TagColor" />
  <EditText
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      style="@style/InputEditText"
      local:MvxBind="Text TagLot" />
  <EditText
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      style="@style/InputEditText"
      local:MvxBind="Text Articles" />
</LinearLayout>

我的ViewModel的代码是:

using Cirrious.MvvmCross.ViewModels;
using MPS_Mobile_Driver.Droid.DataModel;
using MPSDataService;
using System;

namespace MPS_Mobile_Driver.Droid.ViewModels
{
    public class ShipmentViewModel
      : MvxViewModel
    {
        public async void Init(int idno, short idsub)
        {
            Shipment = await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipment(idno, idsub);
            await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipmentInventory (Guid.Parse("59361EA3-C688-41FB-AF96-DF50F357272B"));
            ShipmentInventory = ShipmentDataSource.CurrInventory;
        }

        private Shipment _Shipment;
        public Shipment Shipment
        {
            get { return _Shipment; }
            set { _Shipment = value; RaisePropertyChanged(() => Shipment); }
        }
        private ShipmentInventory _ShipmentInventory;
        public ShipmentInventory ShipmentInventory
        {
            get { return _ShipmentInventory; }
            set { _ShipmentInventory = value; RaisePropertyChanged(() => ShipmentInventory); }
        }
    }
}

除了MvxListView中的细节被填满外,这一切都正常。它显示第一列的值作为整行,其他两列作为空白行,然后冲洗并重复约30项。我的主题模板只是使它成为黑色字母的白色背景。如果是问题,它如下:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="InputEditText" parent="android:style/Widget.EditText">
    <item name="android:textColor">@color/black</item>
    <item name="android:background">@color/white</item>
    <item name="android:textSize">20dp</item>
    <item name="android:textCursorDrawable">@drawable/black_cursor</item>
    <item name="android:layout_margin">5dp</item>
    <item name="android:padding">2dp</item>
  </style>
</resources>

也许我不应该使用线性布局。我希望表格在屏幕上有列。我是Android编程的新手,所以我确信这是我错过的一些小细节。任何帮助将不胜感激。

吉姆

Screen Shot

1 个答案:

答案 0 :(得分:2)

这实际上是一个非常简单的解决方案,因为问题在于我是Android的菜鸟。我所要做的就是在EditTexts上放一个固定的宽度...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <EditText
      android:layout_width="300dp"
      android:layout_height="wrap_content"
      style="@style/InputEditText"
      local:MvxBind="Text TagColor" />
  <EditText
      android:layout_width="300dp"
      android:layout_height="wrap_content"
      style="@style/InputEditText"
      local:MvxBind="Text TagLot" />
  <EditText
      android:layout_width="300dp"
      android:layout_height="wrap_content"
      style="@style/InputEditText"
      local:MvxBind="Text Articles" />
</LinearLayout>
@Stuart感谢你看这个。在将来我在帖子中使用它之前,我将不得不谷歌我的俚语。这意味着我认为它意味着什么,但它有很多其他含义以及O.o

干杯, 吉姆