【发布时间】:2014-10-20 09:30:55
【问题描述】:
大家好,我是 Android 编程的初学者,我正在尝试为我的地图应用程序上的标记制作自定义信息窗口。我的 InfoWindows 必须显示动态图像(我下载并使用 Picasso 库设置)不同的临时标记和一些文本字段,例如“POI”的名称、地址和距离(以分钟为单位)、步行和开车。问题是 InfoWindowAdapter 是图像,所以我看到唯一的方法是强制重新加载标记信息窗口的显示。但是,如果我尝试(正如我在某些论坛和 StackOverflow 上的其他问题中看到的那样),我的应用程序就会崩溃。下面我发布我的代码和评论,可以帮助你和我的应用程序的屏幕。真的谢谢大家。
截图:
代码:
// ****** Custom InfoWindowAdapter ****** //
map.setInfoWindowAdapter(new InfoWindowAdapter() {
View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
@Override
public View getInfoWindow(Marker marker) { //As I've seen on the web, if the marker is null and it is showing infowindow, I do a refresh,
if (marker != null && marker.isInfoWindowShown()){ //but with the debug I've seen that it doesn't never enter in this IF statement and nothing happen when the image is loaded.
marker.hideInfoWindow();
marker.showInfoWindow();
}
return null;
}
@Override
public View getInfoContents(final Marker marker) {
BuildInfoMatrix req = new BuildInfoMatrix();
String nome = marker.getTitle();
String currentUrl = "";
int vuoto = -15;
try{
currentUrl=req.findImageUrl(nome); //from another class (BuildInfoMatrix) I retrieve the right image marker URL to display
}catch(Exception e){
currentUrl = "http://upload.wikimedia.org/wikipedia/commons/b/bb/XScreenSaver_simulating_Windows_9x_BSOD.png"; //If the currentURL is null (I haven't set any URL for the marker) it set an error image
}
if (currentUrl == null)
{
currentUrl = "http://upload.wikimedia.org/wikipedia/commons/b/bb/XScreenSaver_simulating_Windows_9x_BSOD.png";
}
ImageView image;
image = (ImageView) v.findViewById(R.id.image_nuvoletta); //image_nuvoletta is where it will be placed on the InfoWindowAdapter
Picasso.with(v.getContext()) //Here with Picasso I download the image and I set into
.load(currentUrl) //R.id.image_nuvoletta
.error(R.drawable.ic_launcher)
.resize(150, 110)
.into(image, new Callback(){
@Override
public void onSuccess(){
//I should reload here (when the image have been downloaded) the infoWindowAdapter but
//if I place here "marker.showInfoWindow()" the app crash; without, nothing happens.
}
@Override
public void onError(){
}
});
/***********************************/
【问题讨论】:
-
这将导致“stackoverflow 错误”,请查看您的 logcat
-
您认为为什么以及在哪里?我没有在我的 logcat 中发现 stackoverflow 错误..
-
呃,你是对的......但我没有stackoverflow,我的缓存任务的“onpostexecution”有一个空指针异常,你想看看CacheTask吗??
-
我解决了由数组外的 FOR 语句上的索引引起的问题,但这并不能解决“重新加载”自定义 InfoWindowAdapter 的问题。 @BirajZalavadia
-
现在你遇到了哪个错误?
标签: android google-maps infowindow