1

Web (Google マップ マーカー) から画像をダウンロードする非同期タスクがあります。R.drawable.maps1ハードコーディングされたドローアブル マーカーを、取得した画像に置き換えることはできますか?

画像を正しく受信していると思いますが、ここで立ち往生しています。どんな助けでも大歓迎です。

画像ダウンロードタスク

public static class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {

    private String url;

    public ImageDownloadTask(String url) {
        this.url = url;
    }

    protected Bitmap doInBackground(Void... params) {

        final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
        final HttpGet getRequest = new HttpGet(url);

        try {
            HttpResponse response = client.execute(getRequest);
            final int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) {
                Log.w("ImageDownloadTask", "Error " + statusCode
                        + " while retrieving bitmap from " + url);
                return null;
            }

            final HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream inputStream = null;
                try {
                    inputStream = entity.getContent();
                    final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                    Log.w("ImageDownloadTask", "success! "
                            + url);
                    return bitmap;
                } finally {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    entity.consumeContent();
                }
            }
        } catch (Exception e) {
            getRequest.abort();
            Log.w("ImageDownloadTask", "Error while retrieving bitmap from "
                    + url);
        } finally {
            if (client != null) {
                client.close();
            }
        }
        return null;
    }

    protected void onPostExecute(Bitmap bitmap) {
        if (bitmap != null) {

        }

    }
}

マーカーの追加

public void addOverlayItem(double latitude, double longitude, String title, String description)
{
    List<Overlay> mapOverlays = mapView.getOverlays();


    //AsyncTasks.ImageDownloadTask imgTask = new AsyncTasks.ImageDownloadTask("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|c6c6c6");
    //imgTask.execute();

            //can i make use of the bitmap to replace "R.drawable.maps1" below?

    Drawable drawable = this.getResources().getDrawable(R.drawable.maps1);

    OverlayItems itemizedoverlay = new OverlayItems(drawable, this);

    GeoPoint gp = new GeoPoint((int)(latitude * 1E6), (int)(longitude * 1E6));

    OverlayItem overlayitem = new OverlayItem(gp, title, description);

    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);

}

現在のソリューション

new BitmapDrawable(getResources(), imgTask.execute().get());

これは機能しているように見えますが、非常にスマートではありませんよね? を使用せずにこれを達成する方法はあります.get()か?

4

0 に答える 0