Android GoogleMap 2 update information dynamically in InfoWindow with ImageView via Universal Image loader

后端 未结 2 461
鱼传尺愫
鱼传尺愫 2020-12-17 21:33

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(

相关标签:
2条回答
  • 2020-12-17 22:05

    View returned from info window callbacks cannot be updated afterwards.

    Try following this suggestion: Dynamic contents in Maps V2 InfoWindow

    0 讨论(0)
  • 2020-12-17 22: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

    0 讨论(0)
提交回复
热议问题