我正在嘗試使用MvvmCross創建數據條目表。以下是我有:MvvmCross MvxListView和MvxItemTemplate。我如何讓表格正確顯示?
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編程非常陌生,所以我相信這是我錯過的一些小細節。任何幫助將不勝感激。
吉姆
你可能可以添加一個素描圖顯示什麼「頂起」的意思? (對不起,感覺昏暗,谷歌結果爲「頂起來」是堅決nsfw!) – Stuart 2015-03-03 10:17:12
也許一個更好的短語是「不如預期」對白話抱歉。我會想出一個方法來展示它的樣子。 – 2015-03-03 15:11:15
@Stuart我在屏幕上添加了原始帖子的屏幕截圖。請參閱您的想法... – 2015-03-03 16:22:17