I've done the same in my apps for ListView (whether they be in
ListActivity or in a plain Activity) with good success.

I use the java.util.concurrent's ExecutorService to obtain images:

1. Your getView(..) (or bindView/newView/etc) needs to assign an image/
thumbnail (bitmap) to an ImageView. But you don't have the bitmap yet.
If you do have it (store in a limited size cache), just set it .
2. If not, obtain a FutureTask from the ExecutorService and this
FutureTask then will download the image, create a thumbnail from it
and creates a Bitmap from this thumbnail. Remember the id of the image
(can be an id, Uri, URL, whatever, as long as it is unique) and assign
it to the ImageView (setTag()).
3. When ready, the FutureTask will 'post' back to the main-thread that
it has an new thumbnail.
4. On the 'post'-back, loop through the children of ListView, get the
appropriate ImageView, the one whose tag (getTag()) is equal to the
one that FutureTask you got the image for, assign the Bitmap to this
ImageView. This is it.

For myself I created a sub-system of ExecutorService and FutureTask,
called 'Cancelable' tasks, which make it easier to cancel queued up
tasks when they're no longer necessary. But this is an optimization.

On Mar 24, 8:06 am, Mark Murphy <mmur...@commonsware.com> wrote:
> Ivan Soto wrote:
> > Do you have any article/tutorial about the placeholder images to share?
> > I'm trying to find one with no luck.
>
> I have used the technique, but not in code I'm allowed to share. I do
> need to more formally write this up at some point, but I do not have
> anything immediately handy.
>
> The gist of it is that you create your adapter and set it up, in
> getView() or newView()/bindView() (depending on adapter choice), to see
> if the thumbnail has been downloaded. If so, use it for the list row
> being inflated/updated; if not, leave the ImageView in the row pointing
> to some placeholder Drawable resource. This means as the user scrolls,
> she will pick up the thumbnails. Also, at the end, you can quickly
> iterate over the rows (ListView is a ViewGroup, IIRC, so there are
> methods to iterate its children) and ensure each of those rows'
> ImageViews are using their associated thumbnails.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com
> Android App Developer Books:http://commonsware.com/books.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to