skyhigh: thanks for your reply!

> > I haven't tried to do a lazy background image load like you are doing,
> > but have done some code that uses a holder/wrapper to store the layout
> > findViewById which is a nice optimization so that it doesn't have to
> > call inflate and findViewById again when each row is displayed.  My
> > understanding is that when you do this it will allocate enough views
> > for each of the rows that are visible on the screen, and then as a row
> > scrolls off the screen, it will reuse the already initialized view for
> > a new row that is scrolling onto the screen.

As you can see, I have used a view holder pattern too; as was
explained in the Google I/O conference by Romain.

> > In looking at your code I think you may have a problem because of the
> > way that the views for each row get reused when they disappear from
> > sight.  The same view that was used for a row that just disappeared
> > can be reused for a new row that is appearing as the list scrolls.
> > Your getView routine is handling this by detecting that the
> > convertView is non-null when it has already been filled in when this
> > view was used by a previous row.  However you don't have any mechanism
> > to detect when a view has been reused and is now displaying a
> > different row and the URL has changed to a different URL while the
> > background AsyncTask was retrieving the image.  By the time the
> > AsyncTask finishes retrieving the image, the view that it saved the
> > reference to, in order to set the image, could have been reused to
> > display a different row in the list.  If you can add code to check if
> > it is still the expected URL prior to setting the image I think it
> > might solve your problem.  If the URL has changed then skip setting
> > the lazy image on that view, and just add the image to your cache.

Thanks for pointing this out; I was able to recreate the situation
that you've described by inserting a delay in the doInBackground()
method of AsyncTask. Result: When I scrolled a few dozen rows and
stopped, the icons in the new Frame displayed the older icons first
and then the list was refreshed.

I could probably work around this by:
1. Tag the view with some unique Id and when setting the image in the
AsyncTask, find the View by Tag, and then proceed with setImage(..).
2. I think, I could optimize the implementation further by not loading
the image when the list is scrolling; similar to what SlowAdapter does.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to