2016-11-22 4 views
3

私がデバッグモードでビルドしているときは、正常に動作します。 Releaseでビルドするときに、私のMvxListViewが生成されません。MVVMCrossリリースビルドが動作しません(LinkerPleaseInclude Listview)

これはリンカとMvvmCrossがリフレクションマジックを行うために行うことです。そのためリンカはバインドのリンク先を知ることができません。

「LinkerPleaseInclude.cs」というファイルがあり、参照されているようにバインドを偽装するのに役立つという。

どういうわけか私のリストビューがまだ読み込まれません...私を助けてください...

Linkerpleaseincludeファイル:

class LinkerPleaseInclude 
{ 
    public void Include(ICommand command) 
    { 
     command.CanExecuteChanged += (s, e) => 
     { 
      if (command.CanExecute(null)) 
      { 
       command.Execute(null); 
      } 
     }; 
    } 

    public void Include(MvxListView listview) 
    { 
     listview.ItemsSource = new List<int>(); 
     var itemsSource = listview.ItemsSource; 
    } 

    public void Include(AnimalSearchViewModel viewmodel) 
    { 
     viewmodel.FilteredAnimals = new List<AnimalListInfoViewModel>(); 
    } 
} 

AnimalSearchViewModel

public class AnimalSearchViewModel : ViewModelBase 
{ 
    private string searchString; 
    private MvxCommand<AnimalListInfoViewModel> itemSelectedCommand; 

    private readonly IUserDialogs userDialogs; 
    private readonly IAnimalsStorage animalsStorage; 
    private readonly IMapper mapper; 
    private readonly IDebug logger; 

    public IEnumerable<Animal> Animals { get; set; } 
    public IList<AnimalListInfoViewModel> FilteredAnimals { get; set; } 

    public string SearchString 
    { 
     get 
     { 
      return this.searchString; 
     } 
     set 
     { 
      this.FindResults(value); 
     } 
    } 

    public IMvxCommand ItemSelectedCommand 
    { 
     get 
     { 
      this.itemSelectedCommand = this.itemSelectedCommand ?? new MvxCommand<AnimalListInfoViewModel>(this.DoSelectItem); 
      return this.itemSelectedCommand; 
     } 
    } 

    public AnimalSearchViewModel(
     IMvxMessenger messenger, 
     IUserDialogs dialogs, 
     IAnimalsStorage animalsStorage, 
     IMapper mapper, 
     IDebug logger) 
     : base(messenger, "Dierkaart") 
    { 
     this.userDialogs = dialogs; 
     this.animalsStorage = animalsStorage; 
     this.mapper = mapper; 
     this.logger = logger; 
    } 

    public void DoSelectItem(AnimalListInfoViewModel item) 
    { 
     this.ShowViewModel<AnimalListInfoViewModel>(new { id = item.Id }); 
     this.logger.LogInfo(DebugTag.Core, "Key: " + item.Key + " Value: " + item); 
    } 

    protected override async void InitFromBundle(IMvxBundle parameters) 
    { 
     this.Animals = await this.animalsStorage.GetAnimalsAsync(); 

     base.InitFromBundle(parameters); 
    } 

    private void FindResults(string keyword) 
    { 
     this.searchString = keyword; 
     if (this.searchString.Length >= 3) 
     { 
      var filteredAnimals = this.Animals.Where(i => 
                { 
                 // TODO: Get real displayvalue 
                 var displayValue = i.Key; 
                 return displayValue.IndexOf(this.searchString, StringComparison.OrdinalIgnoreCase) != -1; 
                }).ToArray(); 

      this.FilteredAnimals = this.mapper.Map<List<AnimalListInfoViewModel>>(filteredAnimals); 
     } 
     else 
     { 
      this.FilteredAnimals = new List<AnimalListInfoViewModel>(); 
     } 
    } 
} 

layoutfile:

<?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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingTop="?android:attr/actionBarSize" 
    android:fitsSystemWindows="true"> 
    <EditText 
     android:id="@+id/search" 
     android:layout_width="fill_parent" 
     android:layout_height="@dimen/md_list_single_line_with_avatar_item_height" 
     android:paddingLeft="@dimen/md_list_item_horizontal_edges_padding" 
     android:paddingRight="@dimen/md_list_item_horizontal_edges_padding" 
     android:layout_alignParentTop="true" 
     android:drawableLeft="@android:drawable/ic_menu_search" 
     android:inputType="number" 
     android:singleLine="true" 
     android:hint="Type om te zoeken..." 
     local:MvxBind="Text SearchString"/> 
    <Mvx.MvxListView 
     android:id="@+id/select_list" 
     android:scrollbars="vertical" 
     android:layout_below="@id/search" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     local:MvxBind="ItemsSource FilteredAnimals; ItemClick ItemSelectedCommand"/> 
</RelativeLayout> 

ItemsSource FilteredAnimalsが埋め込まれていても、リリースモードでは動作していないと思います。私を助けてください。

+0

あなたは 'Sdk Assemblies Only'または' Sdk and User Assemblies'オプションを使用してリンクしていますか? – Plac3Hold3r

+0

@ Plac3Hold3r SDKアセンブリのみ: – Baklap4

答えて

4

私は問題が直接あなたのEditTextであなたのMvxListViewではなく、テキストの変更に関連していないと信じています。入力した値がViewModelに戻らない場合は、FindResult(string keyword)がトリガーされず、リストFilteredAnimalsが更新されません。

AfterTextChangedイベントをLinkerPleaseIncludeに追加して、リンカーがそれを削除しないようにすることができます。

public class LinkerPleaseInclude 
{ 
    public void Include(TextView text) 
    { 
     text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text; 
     text.Hint = "" + text.Hint; 
    } 
} 
+0

これは成功の鍵でした!しかし、私はまだ疑問に思っています。私は検索バーとしてEditTextを使用しています。なぜTextviewにインクルードを使用しますか? – Baklap4

+1

@ Baklap4では、 'EditText'を使うこともできます。これは、 'EditText'が継承し、' TextView'を使用しているためです。そのため、最も低い基本クラスでリンクすると、すべての継承クラスに対してプロパティ/イベントがリンクされないことが保証されます。 – Plac3Hold3r

+0

説明していただきありがとうございます! – Baklap4

0

LinkerPleaseIncludeのコードで、ItemsSourceプロパティのsetアクセサへの参照が生成されている可能性があります。リンクされないようにするにはgetへの参照が必要です。

はこれを試してみてください:

public void Include(MvxListView listview) 
{ 
    listview.ItemsSource = new List<int>(); 
    var itemsSource = listView.ItemsSource; 
} 
+0

ゲッターが含まれていても、私のリストはまだ空になります.. – Baklap4

関連する問題