Maps V2 InfoWindow中的dynamic内容
我想在Maps V2片段中的标记上显示InfoWindow。 事情是,我想要显示通过图像下载器从网页上dynamic加载的BitMaps。
这是我的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重新加载自己? 当我把 
 marker.showInfoWindow() 
 到onLoadingComplete它创build一个无限循环的标记将popup,开始加载图像,popup自己等。 
 我的第二个问题是,在慢速networking连接(在代码中延迟5000ms的情况下模拟), InfoWindow的ImageView将始终显示上次加载的图像,而不pipe该图像是否属于ImageWindow / Marker 。 
有关如何正确实施这个build议?
 当您收到模型更新时,您应该在当前显示信息窗口的标记上做Marker.showInfoWindow() 。 
所以你需要做3件事情:
-  创build模型,而不是把所有的下载到InfoWindowAdapter
-  保存对标记的引用(称之为markerShowingInfoWindow)
 来自getInfoContents(Marker marker)
- 当模型通知您下载完成呼叫
 if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) { markerShowingInfoWindow.showInfoWindow(); } 
我做了类似的事情。 这仍然给我经济衰退的错误
 if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) { markerShowingInfoWindow.showInfoWindow(); } 
所以我所做的只是closures窗口并再次打开
 if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) { markerShowingInfoWindow.hideInfoWindow(); markerShowingInfoWindow.showInfoWindow(); } 
为更好的细节版本相同的答案这里是我的原始灵魂链接
我也面临同样的情况,并使用下面的代码解决。
在我的适配器中,我添加了公共variables
 public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter { public String ShopName=""; ------- ------- @Override public View getInfoWindow(Marker arg0) { View v; v = mInflater.inflate(R.layout.info_window, null); TextView shop= (TextView) v.findViewById(R.id.tv_shop); shop.setText(ShopName); } } 
并在我的主要活动中添加了MarkerClickListener
 ---- MarkerInfoWindowAdapter mMarkerInfoWindowAdapter; ---- ---- @Override public void onMapReady(GoogleMap googleMap) { mMarkerInfoWindowAdapter = new MarkerInfoWindowAdapter(getApplicationContext()); mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(final Marker arg0) { mMarkerInfoWindowAdapter.ShopName= "my dynamic text"; arg0.showInfoWindow(); return true; } } mMap.setInfoWindowAdapter(mMarkerInfoWindowAdapter); } 
我已经使用了这篇文章中的代码,它运行良好。
http://androidfreakers.blogspot.de/2013/08/display-custom-info-window-with.html