10

I am working on new Google Map v2 API.

I have used ImageLoader to display images dynamically on Marker.

But the problem is when I have got onLoadingComplete() of Universal Image Loader, the ImageView is not invalidated neither automatically nor manually.

Next time if I click on the same Marker, image will be displayed from Cache of Universal Image Loader.

Below is my CustomInfoWindowAdapter code :

private class CustomInfoWindowAdapter implements InfoWindowAdapter {

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        final View mWindow = getLayoutInflater().inflate(R.layout.custom_info_window, null);

        render(marker, mWindow);
        return mWindow;
    }

    private void render(final Marker marker, View view) {

        final String url = markers.get(marker.getId()).getStrProfilePic();
        final ImageView image = ((ImageView) view.findViewById(R.id.badge));
        Log.e(TAG, "URL : " + url);

        if ( url != null && !url.equalsIgnoreCase("null")
                && !url.equalsIgnoreCase("")) {
            imageLoader.displayImage(url, image, options, new SimpleImageLoadingListener() {
                @Override
                public void onLoadingComplete(String imageUri, View view,
                        Bitmap loadedImage) {
                    super.onLoadingComplete(imageUri, view, loadedImage);
                    ((ImageView) view).invalidate();
                }
            });
        } else {
            image.setImageResource(R.drawable.noimage);
        }

        final String title = marker.getTitle();
        final TextView titleUi = ((TextView) view.findViewById(R.id.title));
        if (title != null) {
            titleUi.setText(title);
        } else {
            titleUi.setText("");
        }

        final String snippet = marker.getSnippet();
        final TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
        if (snippet != null) {
            snippetUi.setText(snippet);
        } else {
            snippetUi.setText("");
        }
    }
}

I stores Marker Ids in HashTable when I add Marker. And from their I will get the URL of photo.

Nishant Shah
  • 3,442
  • 5
  • 25
  • 34

2 Answers2

10

I have taken one Marker object at class level and used that object to update the Marker information.

I have Customized my class as below to update the ImageView :

private class CustomInfoWindowAdapter implements InfoWindowAdapter {

    private View view;

    public CustomInfoWindowAdapter() {
        view = getLayoutInflater().inflate(R.layout.custom_info_window, null);          
    }

    @Override
    public View getInfoContents(Marker marker) {

        if ( YourClassName.this.marker != null &&
                ClassName.this.marker.isInfoWindowShown() ) {
            YourClassName.this.marker.hideInfoWindow();
            YourClassName.this.marker.showInfoWindow();
        }
        return null;
    }

    @Override
    public View getInfoWindow(final Marker marker) {
        YourClassName.this.marker = marker;

        final String url = markers.get(marker.getId()).getStrProfilePic();
        final ImageView image = ((ImageView) view.findViewById(R.id.badge));

        if ( url != null && !url.equalsIgnoreCase("null")
                && !url.equalsIgnoreCase("")) {
            imageLoader.displayImage(url, image, options, new SimpleImageLoadingListener() {
                @Override
                public void onLoadingComplete(String imageUri, View view,
                        Bitmap loadedImage) {
                    super.onLoadingComplete(imageUri, view, loadedImage);
                    getInfoContents(marker);
                }
            });
        } else {
            image.setImageResource(R.drawable.noimage);
        }

        final String title = marker.getTitle();
        final TextView titleUi = ((TextView) view.findViewById(R.id.title));
        if (title != null) {
            titleUi.setText(title);
        } else {
            titleUi.setText("");
        }

        final String snippet = marker.getSnippet();
        final TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
        if (snippet != null) {
            snippetUi.setText(snippet);
        } else {
            snippetUi.setText("");
        }

        return view;
    }
}

Check the Example

Nishant Shah
  • 3,442
  • 5
  • 25
  • 34
  • In my application, I do not ave to show multiple maps. But In Map2, it is possible to display multiple maps. Demo is available in android sdk with google play service. – Nishant Shah Apr 24 '13 at 04:25
  • 1
    @NishantShah +1 for your answer but. if you post your blog url in comment than it will easier for whole example :) http://androidfreakers.blogspot.in/ thanks :) – Bhavin Chauhan Aug 12 '13 at 13:40
  • Genius! the only method of refreshing the info window that actually worked for me :D – Matan Dahan Nov 22 '15 at 15:17
3

View returned from info window callbacks cannot be updated afterwards.

Try following this suggestion: Dynamic contents in Maps V2 InfoWindow

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