Ce que je: J'ai un ListView RecyclerView et une fonctionnalité onClick pour elleAfficher un toast en vue à l'aide gestionnaire d'événements dans MvvmCross Xamarin android
Ce que je suis en train: Essayer de montrer un toast en vue utilisant gestionnaire d'événements
MonkeysViewModel.cs
namespace ListView.Core.ViewModels
{
public class MonkeysViewModel : MvxViewModel
{
public MvxObservableCollection<Monkey> Monkeys = new MvxObservableCollection<Monkey>();
private MvxCommand<Monkey> _clickFunction;
public MonkeysViewModel()
{
Monkey m1 = new Monkey
{
Name = "Baboon",
Location = "Africa & Asia",
Details = "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.",
Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
};
Monkeys.Add(m1);
Monkey m2 = new Monkey
{
Name = "Capuchin Monkey",
Location = "Central & South America",
Details = "The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus.",
Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Capuchin_Costa_Rica.jpg/200px-Capuchin_Costa_Rica.jpg"
};
Monkeys.Add(m2);
MonkeyList = Monkeys;
}
public MvxObservableCollection<Monkey> MonkeyList
{
get { return Monkeys; }
set { Monkeys = value; RaisePropertyChanged(() => MonkeyList); }
}
public IMvxCommand clickFunction
{
get { return _clickFunction ?? (_clickFunction = new MvxCommand<Monkey>(OnMemorySelected)); }
}
void OnMemorySelected(Monkey selectedMemory)
{
//Trying to display a Toast message here using event handler and trigger an event in view so I can show a toast
}
}
}
Monkey.cs
namespace ListView.Core.Models
{
public class Monkey
{
public string Name { get; set; }
public string Location { get; set; }
public string Details { get; set; }
//URL for our monkey image!
public string Image { get; set; }
}
}
MonkeysView.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="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark">
<MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxItemTemplate="@layout/listitem_monkey"
local:MvxBind="ItemsSource MonkeyList; ItemClick clickFunction"
/>
</LinearLayout>
MonkeysView.cs
namespace ListView.Droid.Views
{
[Activity(Label = "ListView.Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MonkeysView : MvxActivity
{
protected override void OnViewModelSet()
{
base.OnViewModelSet();
SetContentView(Resource.Layout.MonkeysView);
}
}
}
Vous pouvez également utiliser un plug-in qui vous permet de créer des pains grillés de la ViewModel. Les boîtes de dialogue utilisateur ACR permettent un accès multi-plateforme à différentes boîtes de dialogue à partir des feuilles d'action, des alertes, des confirmations, des toasts, etc. https://www.nuget.org/packages/Acr.UserDialogs/ – Kiliman