如何从url成像到InfoWindowAdapter android?

时间:2013-03-11 18:50:32

标签: android image supportmapfragment

我正在尝试在“InfoWindowAdapter”中显示来自网址的图片  ,我有以下代码,但没有显示图像

....
mMap = getMap();

mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

  ...

 @Override
 public View getInfoContents(Marker marker) {

  View v = getActivity().getLayoutInflater().inflate(
R.layout.info_window_layout, null);

 String image_url = "http://api.androidhive.info/images/sample.jpg";
 new DownloadImageTask(imgEquipo).execute(image_url);
 return v;
 } 
});

调用AsyncTask获取图像

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    public DownloadImageTask(ImageView bmImage) {
        this.bmImage = bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    } }
 }

提供帮助。

1 个答案:

答案 0 :(得分:2)

它不起作用,因为在获取图像之前返回了视图,并且它们未同步。

看看这种方法:

I my using google mapV2 and i m downloading image from google place api and want to display in the popup

诀窍是在获得图像后更新InfoWindow。