1

I'm trying to display an image from a url in a "InfoWindowAdapter" ,I have the following code, but does not show me the image

....
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;
 } 
});

call to AsyncTask to get image

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);
    } }
 }

tranks for your help.

alexis.araya
  • 95
  • 1
  • 10

1 Answers1

2

It won't work because the view is returned before you get the image, and they are not synchronized.

Take a look at this approach:

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

The trick is to update the InfoWindow after you get the image.

Community
  • 1
  • 1
Androiderson
  • 16,865
  • 6
  • 62
  • 72