在地图V2信息窗口的动态内容 [英] Dynamic contents in Maps V2 InfoWindow
问题描述
我要显示在一个地图V2片段标记的信息窗口。 事情是,我想表达的是被动态地从网络与通用图像下载加载位图。
这是我InfoWindowAdapter:
类MyInfoWindowAdapter实现InfoWindowAdapter {
私人最终视图V;
MyInfoWindowAdapter(){
V = getLayoutInflater()。膨胀(R.layout.infowindow_map,
空值);
}
@覆盖
公共查看getInfoContents(标记标记){
项目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选项=新DisplayImageOptions.Builder()
.delayBeforeLoading(5000).build();
imageLoader.getMemoryCache();
imageLoader.displayImage(i.getThumbnailUrl(),IV,期权,
新ImageLoadingListener(){
@覆盖
公共无效onLoadingStarted(字符串imageUri,查看查看){
// TODO自动生成方法存根
}
@覆盖
公共无效onLoadingFailed(字符串imageUri,视图中查看,
FailReason failReason){
// TODO自动生成方法存根
}
@覆盖
公共无效onLoadingComplete(字符串imageUri,
视图中查看,位图loadedImage){
Log.d(图,图片下载+ imageUri);
}
@覆盖
公共无效onLoadingCancelled(字符串imageUri,
查看查看){
// TODO自动生成方法存根
}
});
返回伏;
}
@覆盖
公共查看getInfoWindow(标记标记){
// TODO自动生成方法存根
返回null;
}
}
我有2个问题是:
我们know在信息窗口
绘制,后来改变它(在我的情况下,新的的BitMap
在 ImageView的
)不显示/的信息窗口
未更新。我怎样才能通知信息窗口重新加载自身,当 ImageLoader的
已完成?当我把
marker.showInfoWindow()
到 onLoadingComplete
它创造了一个无限循环,其中的标记会弹出,启动加载图像,弹出自己挂牌等。
我的第二个问题是,在一个缓慢的网络连接(模拟与5000毫秒延迟在code)所示,的ImageView
在信息窗口
如果图像属于该会一直显示上次加载的图像,无论 ImageWindow
/ 标记
。
如何propperly实现这个有什么建议?
您应该做的事 Marker.showInfoWindow()
上标记当前显示的信息窗口,当你收到模型更新。
所以,你需要做3件事情:
- 创建模型,而不是把所有的下载到
InfoWindowAdapter
- 保存参考标记(称之为
markerShowingInfoWindow
)
从getInfoContents(标记标志)
- 当模型通知下载完整的呼叫,你
如果(markerShowingInfoWindow = NULL和放大器;!&安培; markerShowingInfoWindow.isInfoWindowShown()){
markerShowingInfoWindow.showInfoWindow();
}
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.
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;
}
}
I have 2 problems with this:
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()
into onLoadingComplete
it created an infinite loop where the marker will pop up, start loading the image, pop itself up etc.
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?
You should be doing Marker.showInfoWindow()
on marker that is currently showing info window when you receive model update.
So you need to do 3 things:
- create model and not put all the downloading into
InfoWindowAdapter
- save reference to Marker (call it
markerShowingInfoWindow
)
fromgetInfoContents(Marker marker)
- when model notifies you of download complete call
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) {
markerShowingInfoWindow.showInfoWindow();
}
这篇关于在地图V2信息窗口的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!