android - Image cache and display listview

Asked

Viewed 421 times

4

Good afternoon, my friends, The thing is, I’m going to use Volley to get the data from the webservice, and so I write the list to my local BD with Sqlite.

In this webservice will come a JSON with items, each item has its data and an image. I need to cache this image to show in a listview and later in a detail screen. In the future the user will clean these items, thus wiping their images as well.

Well, how can I cache these images and link to each item saved in my BD?

EDIT 1

I will, at 90%, be offline. I will only be online to synchronize and download the updated server items

1 answer

3


How you will adopt various resources to facilitate development, use the Picasso and let him manage it for you.

Through a Target you can intercept and save the image. Example:

public class MeuTarget implements Target
{
    private final WeakReference<ContentResolver> resolver;
    private final String name;
    private final String desc;

    public TargetPhoneGallery(ContentResolver r, String name, String desc)
    {
        this.resolver = new WeakReference<ContentResolver>(r);
        this.name = name;
        this.desc = desc;
    }

    @Override
    public void onPrepareLoad (Drawable arg0)
    {
    }

    @Override
    public void onBitmapLoaded (Bitmap bitmap, LoadedFrom arg1)
    {
       //sua implementacao para guardar o bitmap.
    }

    @Override
    public void onBitmapFailed (Drawable arg0)
    {
    }
}

Picasso.with(context).load(image[position]).into(new MeuTarget(view.getContentResolver(), "nome-imagem", "descricao"));
  • With it I can relate my data saved in the database to the images?

  • @Luangabriel I edited to help. The documentation contains more details.

  • Ah, I forgot to mention: I have to show these images offline. I will only connect to the internet when I synchronize with the server and download the items.

  • Indifferent. With Picasso you get this result.

  • Picasso really solved it. I used the attribute .networkPolicy(NetworkPolicy.OFFLINE) also.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.