我正在使用自定义InfoWindow适配器类来处理用户按下图标以显示某些信息时的标记:
mapView.setInfoWindowAdapter(new CustomMarkerInfoWindowAdapter(downloadService, getLayoutInflater(), markersList));
来自我的自定义InfoWindowAdapter的相关代码段:
@Override
public View getInfoContents(Marker marker) {
final View currentView = inflater.inflate(R.layout.custommarker, null);
final TextView textThing = (TextView) currentView.findViewById(R.id.markerInfoThing);
textThing.setText("Downloading data...");
new Thread() {
public void run() {
Thing thing = downloadService.getThing(thingId);
// this doesn't work - and yes thing.getName() returns a valid string
textThing.setText(thing.getName());
}
}.start();
return currentView;
}
在setText
返回并且InfoWindow上的TextView永远不会更新之后,才会发生对getInfoContents
的第二次调用。我注意到notifyDataHasChanged
中没有其他功能(例如GoogleMap.InfoWindowAdapter
)可以覆盖,因此我想知道是否可以这样做?
答案 0 :(得分:1)
getInfoContents
似乎在下载数据之前返回View
,因此TextView
未更新。
您应先下载内容,然后在下载后更新InfoWindow
。您可以使用AsyncTask
完成此操作,并且可以在InfoWindow
方法调用中显示onPostExecute
,为此,您需要跟踪当前Marker
请参阅以下链接:
this answer还有这种方法:
你应该在标记上做
Marker.showInfoWindow()
当您收到模型更新时,当前显示信息窗口。所以你需要做三件事:
- 创建模型,而不是将所有下载内容放入
CustomMarkerInfoWindowAdapter
- 从
保存对Marker
markerShowingInfoWindow
的引用(称之为getInfoContents(Marker marker)
)- 醇>
当型号通知您下载完成时,请致电
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isShowingInfoWindow()) { markerShowingInfoWindow.showInfoWindow(); }
希望这会对你有所帮助。