2

My project uses the popular LazyAdapter with a listview to fetch remote images on scroll and cache them on the sdcard for later use.

Within another 'screen' of the app I am showing a mapfragment, I would like to display a related image within a CustomInfoWindow on a Google Map View. The idea is to fetch the images if necessary from the server, if the image has already been downloaded previously(either by the list of from the touch of the marker) then it gets it from the sdcard.

To use the ImageLoader with the ListView, you pass the imageview to the ImageLoader along with the remote url (in the adapter getView()) like this:

imageLoader.DisplayImage("http://urltomarkerpic.com" + pic
                    + ".jpg", ((ImageView) view.findViewById(R.id.badge)));

I tried using this within the render() method of my custom info window class (which implements InfoWindowAdapter)and it does work, however the image loads only on the second press of each marker, the first press just shows the default jpg (as specified in the xml). Once the marker i touched again it loads the image from the sdcard (i have confirmed this with logcat).

It seemed intuitive to take this approach and after looking through LadyAdapters code I thought this would work. Has anyone else tried to do this and got it working? Or could anyone suggest an alternate method for reusing the ImageLoader (this will really save me bandwidth) within the InfoWindow whereby both the mapview and listview could utilize the lazy loading mechanism and keep downloading of imges to a minimum

2 Answers2

1

I don't know if you still need the answer, but anyways.. I had the same problem, this happens because the view passed to the infowindow when you initialize it through your adapter is not an actual live view, but a rendered image of it, so it can't update it's contents while it's being showed.

In my case, as in yours, the image loaded on second click, but ended up (kinda) solving it by adding a marker click listener and calling the showInfoWindow() method on marker click event:

map.setOnMarkerClickListener(new OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
        marker.showInfoWindow();
        return false;
    }
}

This loads the InfoWindow again and refreshes the image after it was loaded, without closing it (or at least is so fast that it doesn't look like it). I'm pretty sure it's not the perfect way to do it, but couldn't get to work any other solution I found and after trying it several times worked well enough for what I needed.

If anyone knows a better way to achieve this, glad to hear it.

0

You cannot use image loaders libraries directly, because as stated in the documentation, returned View is not live. If the library you are using has a callback on when the download is completed and Bitmap available without blocking, you may try to integrate that with forcing to show info window again.

You can follow these simple steps from my answer here: Dynamic contents in Maps V2 InfoWindow.

Community
  • 1
  • 1
MaciejGórski
  • 22,187
  • 7
  • 70
  • 94