2015-03-18 53 views
1

我正在使用包含MvxSpinner的MvxListView。當我的應用程序運行時,跟蹤顯示的幾個實例:在旋轉的SelectedItem不允許MvxListView與MvxSpinner在第一個項目上顯示空條目

Null值結合當前

我知道一個事實,數據對象上的條目不爲空。下面是有關代碼:用於MvxListView佈局是

 <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <MvxListView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       local:MvxBind="ItemsSource ShipmentLots.Lots" 
       local:MvxItemTemplate="@layout/inventorylotview" /> 
      <ImageButton 
       android:src="@drawable/ic_action_new" 
       android:layout_width="60dp" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       local:MvxBind="Click NewLot_Clicked" 
       android:id="@+id/btnLotNew" /> 
     </LinearLayout> 

用於MvxItemTemplate佈局是如下:

<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"> 
    <MvxSpinner 
     android:layout_width="130dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     style="@style/InputSpinner" 
     local:MvxItemTemplate="@layout/itemspinner" 
     local:MvxDropDownItemTemplate="@layout/itemspinnerdropdown" 
     local:MvxBind="ItemsSource LotColors; SelectedItem LotColor" 
     android:id="@+id/spinner1" /> 
    <EditText 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     style="@style/InputEditText" 
     local:MvxBind="Text LotNo" /> 
    <ImageButton 
     android:src="@drawable/ic_action_delete" 
     android:layout_width="60dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     local:MvxBind="Click DeleteClicked" 
     android:id="@+id/btnLotDelete" /> 
</LinearLayout> 

的InventoryViewModel如下:

public class InventoryViewModel 
    : MvxViewModel 
{ 
    public async void Init(Guid ID) 
    { 
     await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipmentInventory(ID); 
     ShipmentInventory = ShipmentDataSource.CurrInventory; 

     Shipment = await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipment((int)ShipmentInventory.idno, (short)ShipmentInventory.idsub); 
     ShipmentLots = await MPS_Mobile_Driver.Droid.DataModel.ShipmentDataSource.GetShipmentLotList(Shipment.idno, Shipment.idsub); 
    } 

    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); } 
    } 

    private ShipmentLotList _ShipmentLots; 
    public ShipmentLotList ShipmentLots 
    { 
     get { return _ShipmentLots; } 
     set { _ShipmentLots = value; RaisePropertyChanged(() => ShipmentLots); } 
    } 

    public IMvxCommand NewLot_Clicked 
    { 
     get 
     { 
      return new MvxCommand(() => NewLot()); 
     } 
    } 

    private void NewLot() 
    { 
     ShipmentLot Lot = new ShipmentLot(); 
     Lot.ID = Guid.NewGuid(); 
     Lot.idno = Shipment.idno; 
     Lot.idsub = Shipment.idsub; 
     ShipmentLots.Lots.Add(Lot); 
    } 

} 

視圖模型對於ShipmentLots包含一個名爲Lots的類型ShipmentLot的可觀察集合。 ShipmentLots類是通過WCF服務創建的。我擴展它如下:

public partial class ShipmentLot 
{ 

    private static string[] _LotColors = { "Yellow", "Brown", "White", "Blue", "Orange", "Red", "Green", "Purple" }; 
    public string[] LotColors 
    { 
     get { return _LotColors; } 
    } 

    public IMvxCommand DeleteClicked 
    { 
     get 
     { 
      return new MvxCommand(() => DeleteLot()); 
     } 
    } 

    private void DeleteLot() 
    { 
     MPS_Mobile_Driver.Droid.Views.InventoryView act = (MiscFunctions.CurrActivity as MPS_Mobile_Driver.Droid.Views.InventoryView) ?? null; 
     if (act != null) 
     { 
      act.DeleteLot(this); 
     } 
    } 
} 

這照顧有刪除按鈕的工作和提供MvxSpinner的顏色列表。當我運行該應用程序時,我得到Null值不允許錯誤,並且MvxListView中的第一項在MvxSpinner上顏色不正確。隨後的工作正常。我不確定第一個有什麼不同。任何人對此有任何想法?

感謝, 吉姆

+0

@Stuart你可以看看這個嗎?它應該非常簡單,但是,即使在綁定字段中存在另一個值,微調列表中的第一行上的微調器也會顯示微調列表中的第一個值。 – 2015-03-19 18:25:16

+0

我相信這裏已經回答了這個問題:https://github.com/MvvmCross/MvvmCross/issues/944 – Cheesebaron 2015-03-23 10:45:25

回答

1

從@Cheesebaron和@Stuart我太多的幫助後發現,如果使用MvxSpinner或MvxAutoComplete在一個ItemTemplate的MvxItemList,然後在上面的層次結構內的任何及包括MvxItemlist不能有機器人:layout_height = 「WRAP_CONTENT」。原因在於,如果Android操作系統必須動態確定其高度,則必須多次繪製事物。所有的重繪都會讓綁定中的東西感到困惑。如果你把所有東西都設置爲固定高度,一切正常。要解決上述問題,標記爲MvxItemView上面應該是

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 
     <MvxListView 
      android:layout_width="fill_parent" 
      android:layout_height="300dp" 
      local:MvxBind="ItemsSource ShipmentLots.Lots" 
      local:MvxItemTemplate="@layout/inventorylotview" /> 
     <ImageButton 
      android:src="@drawable/ic_action_new" 
      android:layout_width="60dp" 
      android:layout_height="60dp" 
      android:layout_gravity="center" 
      local:MvxBind="Click NewLot_Clicked" 
      android:id="@+id/btnLotNew" /> 
    </LinearLayout> 

的關鍵似乎是安排你的標識,所以它並沒有以確定的高度預先渲染MvxItemList屏幕截面。您可以參考這個,如果你想看到更多:

https://github.com/MvvmCross/MvvmCross/issues/944

我也有一個如何在做一個MvxItemList內MvxSpinner工作示例:

https://github.com/JimWilcox3/MvxSpinnerTest

這開始爲回購來展示bug。一旦@ Cheesebaron向我展示了什麼是錯誤的,我糾正了它,所以這是一個有效的例子。希望這會幫助某人。

相關問題