0

I am using an ArrayAdapter along with ListView to display some images (I use Picasso to help with image handling). The images are initially loaded from the state on the local device. The adapter has ids for the images, which the getView() method of the adapter uses to get the path. If the image is not available locally, the local state returns an URL for the image. If the URL has expired, I need to fetch this from the backend.

If the URL is not expired, I have no issues, as I can either directly provide the path to Picasso or the URL and Picasso will handle everything for me. However, when I need to fetch the URL from the backend, I need to do this asynchronously. After fetching the URL, I tried doing the following but it doesn't seem to work (my getView() will in this case use Picasso with the URL):

        adapter.remove(id);
        adapter.add(id);

notifyDataSetChanged() doesn't seem to do much as well.

What is the best way to handle this situation? Is there any other way than what I am trying to do with the adapters? I want to delay the URL fetch from the backend as much as possible, basically until the user needs to see the image.

UPDATE: for now, I am replacing the id with a temp_id when the URL is expired and then add the correct id again, when I have the valid URL so that the view gets refreshed.

wislo
  • 1,110
  • 2
  • 13
  • 24

1 Answers1

0

Have you tried clearing your ArrayList of image urls with myArray.clear()? Not so sure if I get your question or how your code looks like.

But I have issues like this before. What worked for me was to repopulating the adapter completely.

This link should help.

Noel Bautista
  • 175
  • 1
  • 12
  • I was worried about keeping a pointer to the data as the base classes could just copy the Arraylist at some point (even though the code doesn't do this at the moment). If I try to keep my own copy, I will have to override all the add/remove methods to make sure my copy is in sync (wanted to try and avoid this mess). Will try out the clear() approach, but IIRC, I did try this and it didnt work. – wislo May 01 '15 at 13:08