0

I don't know how to get several images from a URL.

Those images come in as Bitmap; I need to convert them to drawable, but I don't know how.

Drawable icon = getResources().getDrawable(R.drawable.icon);

Am I doing it correctly calling the url(images), or is there a better way to do that?


This is the asynctask where I get the images

 private class BajarImagenTask extends AsyncTask<String, Void, Bitmap> {
        @Override
        protected Bitmap doInBackground(String... urls) {

         return BajarImagen(urls[0]);
        }

         protected void onPostExecute(Bitmap result){       

         Drawable icon = getResources().getDrawable(R.drawable.icon);

                point.setImage(d);


         }
     }

This the connection:

 private Bitmap BajarImagen (String URL)
        {

         Bitmap bitmap  = null;
         InputStream in = null;
         try {
             in=OpenHttpConnection(URL);
             bitmap=BitmapFactory.decodeStream(in);
             in.close();
         }
         catch (IOException e1) {

         }

         return bitmap;
        }

Here is the method with a "FOR" inside to get several URLs and calling many times the asynctask

 public void datosDesdeElXML(String[][] datos) {


    for(int i = 0; i < moteles.length;i++){


        String motel[] = moteles[i];


        double lat = Double.valueOf(motel[0].trim());
        double lng = Double.valueOf(motel[1].trim());

        String name = motel[2].trim();
        String address = motel[3].trim();
        **String urldefotoglobo = motel[4].trim();**
      // here i get url from server in a xml format


        String aidis = motel[5].trim();

        **new BajarImagenTask().execute(urldefotoglobo);**
         // Here i call the asynctask 
          }
      }
KatieK
  • 13,586
  • 17
  • 76
  • 90
pablete
  • 101
  • 2

0 Answers0