MvvmCross: What is the best way to get the selected item from the MvxListView in Android?

I am using MvvmCross v3.06 and I have defined MvxListView in android linked to a list. I see a list, but I can’t find a better way to get the item that is selected when I click on it.

I am currently doing the following in OnCreate for this operation, but this is not particularly MVVM, and I wondered if there is a better way to bind?

var list = FindViewById<MvxListView>(Resource.Id.subslist); list.ItemClick = ((MyViewModel)ViewModel).ItemSelectedCommand; 

I cannot find any documentation on the best way to do this, so any help would be great.

+6
source share
1 answer

For android, the most common method is to bind ItemClick to MvxCommand<TItem> - so use:

  local:MvxBind="ItemClick ItemSelectedCommand" 

This can be seen in the examples, including:


Less common (so far) for Android, you can also bind to a custom binding SelectedItem on MvxListView

This method is shown on Spinner ( MvxSpinner ) in MoreControls - https://github.com/slodge/MvvmCross-Tutorials/blob/master/MoreControls/MoreControls.Droid/Resources/Layout/FirstView.axml (this example is built live on video time N = 18 - see http://youtu.be/s1LhXdCTsn4?t=7m26s

+11
source

Source: https://habr.com/ru/post/945613/


All Articles