After search a lot for my problem, i see all work fine Just for my test, I never scroll to see the result so ive a last problem i dont understand.
The first time the listview is call, all pics are loaded in the first line . But after, if I scroll down, picts are loaded in the good lines, and If I scroll up, its ok too Have an idea? De : monodroid-boun...@lists.ximian.com [mailto:monodroid-boun...@lists.ximian.com] De la part de Stuart Lodge Envoyé : lundi 19 mars 2012 09:35 À : Discussions related to Mono for Android Objet : Re: [mono-android] Asynchronous display pics into listview There are several ways to get something like this to work. One simple way is to maintain a dictionary of row numbers (position) to ImageView's - that way the row number can be your unique number. You do of course need to make sure that your dictionary is kept up to date if your convertView's get reused. e.g. you could do something like: private Dictionary<int, ImageView> _imageLookup; public override View GetView(int position, View convertView, ViewGroup parent) { lock(this) { var view = (convertView ?? inflater.Inflate(Resource.Layout.DialogCategoriesLigne, parent, false)) as LinearLayout; var ImageItem = view.FindViewById(Resource.Id.imageItemDialogCategoriesLigne) as ImageView; foreach (var kvp in _imageLookup) { if (kvp.Value == ImageItem) { _imageLookup.Remove(kvp.Key); break; } } _imageLookup[position] = ImageItem; KickOffAsyncSearchHere(position); var Description = view.FindViewById(Resource.Id.descriptionDialogCategoriesLigne) as TextView; var Nbimages = view.FindViewById(Resource.Id.nbimgDialogCategoriesLigne) as TextView; ImageItem.SetImageResource(Resource.Drawable.DefaultImageMenu); Description.SetText(listetext[position].description); Nbimages.SetText(listetext[position].description); return view } } // async thread comes in here somehow private void ImageSearchComplete(int position, Drawable drawable) { RunOnUIThread(() => UIImageSearchComplete(position drawable)); } // called on UI thread - but use lock anyway private void UIImageSearchComplete(int position, Drawable drawable) { lock (this) { ImageView imageView; if (!_imageLookup.TryGetValue(position, out imageView) return; imageView.SetDrawable(drawable); } Another way to do this is to wrap up the logic inside a subclassed ImageView. I've recently coded something like this for this class - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross. Binding/Android/Views/MvxHttpImageView.cs Which internally uses this helper: https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/ Platform/Images/MvxDynamicImageHelper.cs - which in turn uses a "disk" and in-memory caching framework - a bit like the code in monotouch.dialog If you don't care abour disk and in-memory caching, then you should be able to hack something up quite quickly. Stuart On 18 March 2012 17:37, Michel <michel.wa...@gmail.com> wrote: Hello. To display asynchonous pics to my listview, with one or more http connexions, i wrote a special thread, and change Imageitem.setImageDrawable. But there is a problem with this system.... i must put a unique id for each ImageView in listview, load the item ImageView into a list, and just view.Addview(Imageitem) if item imageview is not null to not do a new ImageView() when Getview is call But GREF inscrease :(, and application crash if i scroll lot of! The best Getview to not have increase GREF (0 increase more), is : public override View GetView(int position, View convertView, ViewGroup parent) { var view = (convertView ?? inflater.Inflate(Resource.Layout.DialogCategoriesLigne, parent, false)) as LinearLayout; var ImageItem = view.FindViewById(Resource.Id.imageItemDialogCategoriesLigne) as ImageView; var Description = view.FindViewById(Resource.Id.descriptionDialogCategoriesLigne) as TextView; var Nbimages = view.FindViewById(Resource.Id.nbimgDialogCategoriesLigne) as TextView; ImageItem.SetImageResource(Resource.Drawable.DefaultImageMenu); Description.SetText(listetext[position].description); Nbimages.SetText(listetext[position].description); return view } The problem with it, i can't put a unique Id to my ImageItem, and in my independant Thread, i can't change the pic. If i just do in my independant thread a ImageItem.setImageDrawable, all pics are loaded in the first listview item.... Somone have a idea ? _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid