通过通用图像装载Android的GoogleMap的2更新信息动态的信息窗口与ImageView的信息、图像、窗口、动态

2023-09-06 01:50:04 作者:故人怎追忆

我工作的新的谷歌地图V2 API。

I am working on new Google Map v2 API.

我已经使用ImageLoader的动态上标记显示图像。

I have used ImageLoader to display images dynamically on Marker.

但问题是,当我有()的通用图像装载机onLoadingComplete,ImageView的不失效既不是自动还是手动。

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.

下面是我的 CustomInfoWindowAdapter code:

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("");
        }
    }
}

我店标记的ID在哈希表当我添加标记。而从他们我会得到照片的网址。

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

推荐答案

我已在一流水平的一个标志物,并使用该对象更新标记信息。

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

我已经定制为我下面的类来更新ImageView的:

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;
    }
}

检查为例