4

I am using Sergey Tarasevich's library Universal Image Loader in my Android project to load images into a ListView. At the moment I am loading my pictures in the getView() method in my adapter and everything works as expected.

The problem is I want to load some images (three or four) in advance so that the user doesn't need to wait for the images to load when scrolling. What would be the best approach to achieve this using Universal Image Loader?

Qw4z1
  • 3,041
  • 1
  • 24
  • 36
  • Will this be the same images, again and again? If so, just enable caching, it's closer to the bottom of your URL. Caching is disabled by default - you can enable it so you only take the loading penalty the first time. – Ewald Dec 28 '12 at 08:47
  • @Ewald Not that simple, I'm afraid. The list is a list of friends with profile pictures. I do, however, cache them, both on disc and in memory, but the problem is that I (down)load them in getView. Wich only get called when the image already should be present to avoid showing the stub. – Qw4z1 Dec 28 '12 at 08:54
  • Then the only alternative I know if is to do the loading in an AsyncTask - something that runs in the background and that updates the UI as these images become available. – Ewald Dec 28 '12 at 09:09
  • @Ewald Yes, but that is basically what UIL does. – Qw4z1 Dec 28 '12 at 09:19
  • That is true - I thought you could spawn it in the background while doing something else. – Ewald Dec 28 '12 at 10:25

1 Answers1

11

You can use loadImage(...) for following images in getView(...) to pre-cache them.

nostra13
  • 12,377
  • 3
  • 33
  • 43
  • 1
    So.. you mean that when I'm at position x in getView I use loadImage on position x+1, x+2 etc? – Qw4z1 Dec 30 '12 at 14:24
  • Yes, something like that. You can try it, maybe it helps. – nostra13 Dec 30 '12 at 14:29
  • Now using this combined with a listener to preload downwards or upwards. just preloading one give a big boost to the user experience. – Qw4z1 Jan 11 '13 at 08:00
  • 2
    what did you do to preload images? can you post some code that made a change while loading images from universal imageloader – Sharmilee Apr 17 '13 at 05:44
  • When scrolling fast and preloading more than one image, ``loadImage()`` gets called multiple times for the same URI. Is your library aware of that and doesn't start loading the same URI concurrently? – Julian Sievers Nov 04 '13 at 10:29
  • Actually it does but for `displayImage`. If you call `loadImage(...)` multiple times in one moment then you got multiple requests. – nostra13 Nov 18 '13 at 15:22