我刚刚在AsyncTask
下载和更新时遇到了类似的问题,InfoWindow
今天早上我把头撞在墙上后,我想出了这个小解决方法,希望能满足您的需求,直到谷歌解决这个问题。
我正在调用mymarker.showInfoWindow()
的方法,该方法重新调用了这些方法,这些方法最终进入一个循环并且从未正确传播我的更改。OnPostExecute()
AsyncTask
InfoWindowAdapter
我使用的解决方案是存储当前选择的标记和InfoWindow
我想要显示的视图。我已经在下面的示例中进行了TextView
更新DownloadBubbleInfo
AsyncTask
(我相信类似于您的图像线程)。
// Setting a custom info window adapter for the google map
gMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
public View getInfoContents(Marker arg0) {
if (selectedMarker.isInfoWindowShown()) {
return infoWindowView;
} else {
// Getting view from the layout file info_window_layout
infoWindowView = getLayoutInflater().inflate(
R.layout.bubblewindowlayout, null);
// Stash the base view in infoWindowView
// Getting reference to the TextView to set latitude
TextView tvTit = (TextView) infoWindowView
.findViewById(R.id.tv_title);
tvTit.setText("Fetching data...");
// Async the update so we're not slowed down waiting for
// the
// bubble to populate
new DownloadBubbleInfo(context, infoWindowView, arg0)
.execute(arg0.getTitle(), arg0.getSnippet());
// Returning the view containing InfoWindow contents
return infoWindowView;
}
}
});
gMap.setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
// When a marker is clicked set it as the selected marker so
// we can track it for the InfoWindow adapter. This will
// make sure that the correct marker is still displayed when
// the callback from DownloadBubbleInfo is made to
// marker.showInfoWindow() which is needed to update the
// InfoWindow view.
selectedMarker = marker;
infoWindowView = null;
return false;
}
});
以及来自的相关行DownloadBubbleInfo
AsyncTask
:
@Override
protected String[] doInBackground(String... queryparts) {
// Do the query and stash the results in queryResults and pass to
// onPostExecute to attach to the mainview (the current view from the
// main code) and then call showInfoWindow on the marker to re-launch
// the InfoWindowAdapter methods again to repopulate the InfoWindow view
// and attach it.
return queryResults;
}
protected void onPostExecute(String[] results) {
((TextView) mainview.findViewById(R.id.tv_title)).setText(results[0]);
((TextView) mainview.findViewById(R.id.tv_info)).setText(results[1]);
marker.showInfoWindow();
Log.i("Chris-Debug", "Reshowing InfoWindow");
}
现在,所有这些都应该确保正确的标记填充了从您返回的正确信息AsyncTask
,嘿,很快就成功绕过了极其尴尬的 GoogleMaps v2 for Android API 的另一个角落!