6

I have an array of all the URIs of the images which I am showing in a List. Now I want to run a thread in background which gets this images from web and store them on the SD card. So when I click a particular element in the list instead of fetching from web it should fetch from the SD card in the new activity.

How do I do this?

Macarse
  • 91,829
  • 44
  • 175
  • 230
Ameya Phadke
  • 923
  • 1
  • 13
  • 18
  • Read this thread, there are a lot of information. http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview I prefer Android-Universal-Image-Loader library https://github.com/nostra13/Android-Universal-Image-Loader, but you can find other solutions also. hope it helps. – Tadas Valaitis Aug 10 '12 at 12:08

3 Answers3

2

You could try using my lazy-drawables framework (GPL v3 licensed):

https://github.com/rtyley/lazy-drawables

-unfortunately it's not quite ready for production yet, but among the things it attempts to handle:

  • background (non-UI-thread) loading of image resources
  • efficient caching of scaled bitmaps - for the use-case where you're downloading a single big-ish image, and want to show it hundreds of times in a smaller icon format in a listview or something
  • transparency of use, by which I mean...

...once you have a lazy-drawable session set up, populating an image view is as easy as:

Drawable avatarDrawable = imageSession.get(someUserIdentifier); // doesn't block
imageView.setImageDrawable(avatarDrawable);

You don't care that it may have immediately returned you a normal bitmapdrawable, or possibly spawned an async task and returned a placeholder drawable - the drawable will update itself and it's host ImageView when the async task has completed.

That's the theory anyway. It seems to sorta-kinda work so far, but sometimes that spontaneous UI update doesn't happen... not sure why :-}

Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
Roberto Tyley
  • 24,513
  • 11
  • 72
  • 101
0

Check WebImageView by matthias käppler.

You can replace his way of caching images with the SDcard feature you want.

Macarse
  • 91,829
  • 44
  • 175
  • 230
0

Use AsyncTask download in the background while show your UI

    File imageFile;

Save Images from web

public View getView(int position, View convertView, ViewGroup parent) {    
    imageFile = new File("/sdcard/jorgesysTemp/" + Arraypicname(position);
    if(!imageFile.exists()){ 
     AsyncTaskProcess() //Download your images to sdcard
    }

When you click your listview load the image from sdcard

    @Override
    protected void onListItemClick(ListView l, View v, final int position, long id) {
     //load from sdcard
        Bitmap bitmapImg = BitmapFactory.decodeFile("/sdcard/jorgesysTemp/" + Arraypicname(position));
        BitmapDrawable drawableImg = new BitmapDrawable(bitmapImg );                
        myimageview.setImageDrawable(drawableImg );
...
...
...     
Jorgesys
  • 124,308
  • 23
  • 334
  • 268