public override Android.Views.View GetView(int position, Android.Views.View convertView, ViewGroup parent) { if (App.Locator.ModeZone.InvalidViews) { InvalidateAllViews(); } // on récupère l'alerte en question var item = this[position]; // on essaie de récupérer la vue potentiellement déjà créé ListAlertModeZoneViewHolder holder = null; if (!_alreadyCreatedViews.ContainsKey(position)) { _alreadyCreatedViews.Add(position, null); } Android.Views.View view = _alreadyCreatedViews[position]; // si on a récupéré la vue on récupère le holder dans son tag if (view != null) { holder = view.Tag as ListAlertModeZoneViewHolder; } // si le holder n'est pas défini, on le fait et on crée la vue if (holder == null) { holder = new ListAlertModeZoneViewHolder(); view = _context.LayoutInflater.Inflate(Resource.Layout.ListAlertModeZoneRow, null);//pour une ligne ? view.Tag = holder; holder.titre = view.FindViewById <TextView>(Resource.Id.listAlertsModeZoneRow_titre); holder.description = view.FindViewById <TextView>(Resource.Id.listAlertsModeZoneRow_contenu); holder.nbrRecipients = view.FindViewById <TextView>(Resource.Id.listAlertsModeZoneRow_nbrRecipients); { var alertWithRecipient = ((AlertWithRecipientDTO)item); // updates the contents of the holder UpdateHolderContents(holder, alertWithRecipient); // attaches the click event (edit alert) on the view view.Click += ((object o, EventArgs e) => { App.Locator.ModeZone.GoToAlertDetail(alertWithRecipient, position); }); } _alreadyCreatedViews[position] = view; } // if the holder exists, we may need to update its properties else { UpdateHolderContents(holder, (AlertWithRecipientDTO)item); } return(view); }
/// <summary> /// Updates the content of one holder /// </summary> private void UpdateHolderContents(ListAlertModeZoneViewHolder holder, AlertWithRecipientDTO contents) { holder.titre.Text = contents.Title; holder.description.Text = contents.Content; holder.nbrRecipients.Text = contents.LsRecipients != null?contents.LsRecipients.Count.ToString() : "0"; }