Android 动态显示到InfoWindow Googlemap V2

Android 动态显示到InfoWindow Googlemap V2,android,android-imageview,google-maps-android-api-2,infowindow,Android,Android Imageview,Google Maps Android Api 2,Infowindow,我正在开发一个旅游应用程序。在GoogleMapAPIv2功能上,我希望每个信息窗口都有不同的图像 我已经为自定义标题和详细信息文本覆盖了WindowInfoAdapter public class MyInfoWindowAdapter implements InfoWindowAdapter { private final View mView; public MyInfoWindowAdapter(Activity activity) { mView =

我正在开发一个旅游应用程序。在GoogleMapAPIv2功能上,我希望每个信息窗口都有不同的图像

我已经为自定义标题和详细信息文本覆盖了WindowInfoAdapter

public class MyInfoWindowAdapter implements InfoWindowAdapter {
    private final View  mView;
    public MyInfoWindowAdapter(Activity activity) {
        mView = activity.getLayoutInflater().inflate(R.layout.custom_info_window, null);
    }
    @Override
    public View getInfoContents(Marker marker){
        String title = marker.getTitle();
        final String snippet = marker.getSnippet();
        final TextView titleUi = (TextView) mView.findViewById(R.id.title);
        // final View subtitleUi = mView.findViewById(R.id.subtitle);
        final TextView snippetUi = ((TextView) mView.findViewById(R.id.snippet));
        final TextView placeid = ((TextView) mView.findViewById(R.id.placeid));
        final RatingBar voteUi = ((RatingBar) mView.findViewById(R.id.ratingBar1));
        final ImageView imageUi = ((ImageView) mView.findViewById(R.id.imageView1));
        titleUi.setText(title);

        //other code
        return mView;
    }

    @Override
    public View getInfoWindow(Marker marker){
        return null;
    }
}
它很好用,因为它是一根绳子。 现在我想使用ImageView在InformWindow上添加一个图像。 出现这个问题是因为我使用了来自断言和流的图像。是这样的

InputStream ims = getSherlockActivity().getAssets().open("images/" + imageSubPath + "/" + splitedImages[i].toLowerCase());
Drawable iImages = Drawable.createFromStream(ims, null);

我不能像以前处理字符串那样将可绘制对象放入代码段。 我想要的结果是:


如何在信息窗口上显示图像,任何建议都很好

您必须创建额外的数据结构来保存图像,例如:

Map<Marker, Drawable> allMarkersMap = new HashMap<Marker, Drawable>();
在getInfoContents中:

并将其添加到ImageView


另一种方法是使用,它有Marker.setDataObject和Object Marker.getData等方法。您可以使用它直接将Drawable分配给marker,就像处理snippet一样。

您必须创建其他数据结构来保存图像,例如:

Map<Marker, Drawable> allMarkersMap = new HashMap<Marker, Drawable>();
在getInfoContents中:

并将其添加到ImageView


另一种方法是使用,它有Marker.setDataObject和Object Marker.getData等方法。您可以使用它直接将Drawable分配给marker,就像处理snippet一样。

在挠头三个小时后,我用postDelayed处理程序解决了这个问题。 其思想是:例如,包含infoWindow数据的对象必须具有一些可绘制的字段图像。当您第一次显示infoWindow时,一些异步进程或另一个异步进程会获取图片并将其还原到图像中。您必须设置postDealyed runnable,这将每隔X毫秒检查一次图像值,如果它变为非空,则重新显示infoWindow,否则-设置另一个postDelayed运行。getInfoContents代码的我的部分:

  final One o=data.get(id);
  View v=o.inflateMarkerInfo(this);
  if (o.image==null) {
    final Handler h=new Handler();
    h.postDelayed(new Runnable() {
      @Override
      public void run() {
        if (o.image!=null) m.showInfoWindow();
        else h.postDelayed(this, 100);
      }
    }, 100);
  }
  return v;

当然,您可以在第一次调用时返回null,这样您的信息窗口在获得图像之前不会显示,但这会导致一些延迟。

在我挠头三个小时后,我用postDelayed handler解决了这个问题。 其思想是:例如,包含infoWindow数据的对象必须具有一些可绘制的字段图像。当您第一次显示infoWindow时,一些异步进程或另一个异步进程会获取图片并将其还原到图像中。您必须设置postDealyed runnable,这将每隔X毫秒检查一次图像值,如果它变为非空,则重新显示infoWindow,否则-设置另一个postDelayed运行。getInfoContents代码的我的部分:

  final One o=data.get(id);
  View v=o.inflateMarkerInfo(this);
  if (o.image==null) {
    final Handler h=new Handler();
    h.postDelayed(new Runnable() {
      @Override
      public void run() {
        if (o.image!=null) m.showInfoWindow();
        else h.postDelayed(this, 100);
      }
    }, 100);
  }
  return v;

当然,您可以在第一次调用时返回null,这样在获得图像之前您的信息窗口不会显示,但这会导致一些延迟。

我无法像以前使用String时那样将Drawable对象放入snippet-为什么不?@Commonware,因为snippet的参数是String。我用手分开处理绳子;在getInfoContents中,我使用String.Split。但是图像是可绘制的啊,对不起,我以前误解了。现在我明白了。没问题,谢谢你阅读并回答我的问题:我不能像以前处理String那样将Drawable对象放到snippet中-为什么不能?@Commonware,因为snippet的参数是String。我用手分开处理绳子;在getInfoContents中,我使用String.Split。但是图像是可绘制的啊,对不起,我以前误解了。现在我明白了。没问题,谢谢你们阅读并回答我的问题:谢谢你们的想法,它成功了。只需创建全局HashMap。不是最好的解决办法,但解决了我的问题。如果我有更多的时间写我的论文,我会尝试Android地图扩展:谢谢你的想法,它成功了。只需创建全局HashMap。不是最好的解决办法,但解决了我的问题。如果我有更多的时间写论文,我会尝试Android地图扩展: