How to Bind data to a Custom ListView with Xamarin Android with Reactive UI

久未见 提交于 2019-12-06 13:39:02

You would use an adapter to accomplish this on Android, just like you would without Reactive Extensions.

In case you want to use a ListView with RxUI, you'd use a ReactiveListAdapter. Unfortunately this isn't really documented yet, so you might want to take a look at the source code: https://github.com/reactiveui/ReactiveUI/blob/develop/src/ReactiveUI/Platforms/android/ReactiveListAdapter.cs

The gist is you create an instance with the ReactiveList supplying the data. The adapter then watches for changes in this list to know when it needs to be updated.

Example:

this.WhenAnyValue (view => view.ViewModel.OutletListing)
    .Where (listing => listing != null)
    .Select (listing => new ReactiveListAdapter (listing, MyViewCreator))
    .BindTo (this, view => view.List.Adapter);

MyViewCreator is a delegate which accepts the initial ViewModel from your list and the parent ViewGroup so you can inflate the row with initial data and return the resulting View.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!