How to image from url into InfoWindowAdapter android?

非 Y 不嫁゛ 提交于 2019-12-11 10:01:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15346254/how-to-image-from-url-into-infowindowadapter-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!