Maps V2 InfoWindow 中的动态内容 [英] Dynamic contents in Maps V2 InfoWindow

查看:30
本文介绍了Maps V2 InfoWindow 中的动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Maps V2 片段中的标记上显示一个信息窗口.问题是,我想展示使用 Universal Image Downloader 从网络动态加载的位图.

I want to show an InfoWindow on markers in a Maps V2 fragment. Thing is, I want to show BitMaps that are dynamically loaded from the web with Universal Image Downloader.

这是我的 InfoWindowAdapter:

This is my InfoWindowAdapter:

class MyInfoWindowAdapter implements InfoWindowAdapter {

    private final View v;

    MyInfoWindowAdapter() {
        v = getLayoutInflater().inflate(R.layout.infowindow_map,
                null);
    }

    @Override
    public View getInfoContents(Marker marker) {



        Item i = items.get(marker.getId());

        TextView tv1 = (TextView) v.findViewById(R.id.textView1);
        ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
        tv1.setText(i.getTitle());


        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .delayBeforeLoading(5000).build();

        imageLoader.getMemoryCache(); 

        imageLoader.displayImage(i.getThumbnailUrl(), iv, options,
                new ImageLoadingListener() {

                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,
                            FailReason failReason) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onLoadingComplete(String imageUri,
                            View view, Bitmap loadedImage) {
                        Log.d("MAP", "Image loaded " + imageUri);

                    }

                    @Override
                    public void onLoadingCancelled(String imageUri,
                            View view) {
                        // TODO Auto-generated method stub

                    }
    });

        return v;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        // TODO Auto-generated method stub
        return null;
    }

}

我有两个问题:

正如我们知道InfoWindow 已绘制并随后发生更改对此(在我的情况下,ImageView 上的新 BitMap)未显示/InfoWindow 未更新.imageLoader 完成后,如何通知"InfoWindow 重新加载?当我把

As we know the InfoWindow is drawn and later changes to it (in my case the new BitMap on the ImageView) are not shown/ the InfoWindow is not being updated. How can I "notify" the InfoWindow to reload itself when the imageLoader has finished? When I put

marker.showInfoWindow()

进入 onLoadingComplete 它创建了一个无限循环,标记将弹出,开始加载图像,弹出自身等.

into onLoadingComplete it created an infinite loop where the marker will pop up, start loading the image, pop itself up etc.

我的第二个问题是在慢速网络连接上(用代码中的 5000ms 延迟模拟),InfoWindow 中的 ImageView 将始终显示最后加载的图像,无论该图像是否属于该 ImageWindow/Marker.

My second problem is that on a slow network connection (simulated with the 5000ms delay in the code), the ImageView in the InfoWindow will always display the last loaded image, no matter if that image belongs to that ImageWindow/ Marker.

关于如何正确实施这一点有什么建议吗?

Any suggestions on how to propperly implement this?

推荐答案

当您收到模型更新时,您应该对当前显示信息窗口的标记执行 Marker.showInfoWindow().

You should be doing Marker.showInfoWindow() on marker that is currently showing info window when you receive model update.

所以你需要做三件事:

  1. 创建模型而不是把所有的下载都放到InfoWindowAdapter
  2. 保存对 Marker 的引用(称之为 markerShowingInfoWindow)
    来自 getInfoContents(Marker 标记)
  3. 当模型通知您下载完成调用

if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) {
    markerShowingInfoWindow.showInfoWindow();
}

这篇关于Maps V2 InfoWindow 中的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆