I change all my code :) But I've a last problem I don't understand.

First, my items for the GetView are in a list<>, who contain :

A int for the Id of my ImageView,
A linearlayout (default null)
A TextView (default null)
A TextView(default null)
And a ImageView  (default null)


So now, in the View GetView, if linearlayout is null, I initialize it and
other properties, and put to the ImageView a
.SetImageResource(Resource.Drawable.DefaultImageMenu);

I've no problem, work very fine, very very fast. When I scroll, I see needed
items in View GetView, ok..

A the end of the View GetView, I've another List, who I put, if
ImageView.isShown(), for asynchronous download pics, the pic to change in
the ImageView (a permanent other thread who is launched at the beginning of
the application).

In this other thread, if ImageView.isShown(), he download the pic, and
change the pic by a
(ImageView)Imageview.FindViewById(Id)).SetImageDrawable(ImageFromInternet);

I don't understand why, after each changement of the pic, he return to the
View GetView for this item.

It's for me a problem because, when he return to the View GetView, he ask to
my other thread to rechange again the pic (who is already print to the
screen!), and when the other pic change the pic, he return to the View
GetView etc etc etc..

Someone have a idea?




-----Message d'origine-----
De : monodroid-boun...@lists.ximian.com
[mailto:monodroid-boun...@lists.ximian.com] De la part de Jonathan Pryor
Envoyé : jeudi 15 mars 2012 15:32
À : Discussions related to Mono for Android
Objet : Re: [mono-android] bug into listview (monodroid bug ?)

And for those not on #monodroid...

On Mar 15, 2012, at 7:07 AM, Michel wrote:
...
> -- Class ListViewCategories --
> public class ListViewCategories : BaseAdapter
...
>               public override View GetView (int position, View
convertView, ViewGroup parent)

The intent of the `convertView` parameter is to reuse an existing instance
that you allocated, thus reducing the number of objects that exist, reducing
memory pressure, and keeping performance up:

        
http://androidapi.xamarin.com/?link=M:Android.Widget.IAdapter.GetView

        convertView:
                 The old view to reuse, if possible.

The problem? While `convertView` is checked:

>            View vi = convertView;
>            if (convertView == null)
>            {
>                //Log.Debug("--> ConvertView null");
>                vi = inflater.Inflate(Resource.Layout.DialogCategories,
null);
>               // Log.Debug("<-- ConvertView null");
>            }

...nothing is done with it. Instead, a new view is always created and
returned:

>            LinearLayout view = new LinearLayout(context);
...
>                       return view;
>               }

The result, as you see, is a constantly increasing gref count.

There are two solutions here:

1. Call GC.Collect() more often so that the unused LinearLayout instances
will be collected. However, this may or may not work; it depends on what
Android does with the returned instances. If it retains a reference to all
of them, then they will never be collected.

2. Use the `convertView` parameter as it is intended: actually reuse the
view. For example, in this instance the `convertView` will likely be a
LinearLayout instance, as constructed by the GetView() method, so you could
grab the already existing TextView instances and change their strings
instead of creating a new LinearLayout + TextView object graph.

 - Jon

_______________________________________________
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

Reply via email to