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.