title: Download and Save Images Using Picasso
body: <p>I'm trying to show my <strong>news</strong> in a custom <strong>ListView</strong>. Each <strong>news</strong> is included of some <strong>images</strong> and I want to </p>
  
  <p>1.download <strong>images</strong> from server</p>
  
  <p>2.save in local storage</p>
  
  <p>3.save <strong>path</strong> of <strong>images</strong> into SQLite</p>
  
  <p>4.show <strong>images</strong> in ListView using my custom adapter.</p>
  
  <p>I just have problem with steps <strong>1</strong> &amp; <strong>2</strong>. I can get <strong>news</strong> from server and show them in my <strong>ListView</strong> </p>
  
  <p>and show <strong>images</strong> from cache by add below code in my adapter:</p>
  
  <pre><code>Picasso.with(context).load(image[position]).into(iv);
  </code></pre>
  
  <p>By using <code>Picasso.with(context).load(image[position]).into(target)</code> , just I can save one </p>
  
  <p><strong>image</strong> in storage.</p>
  
  <p>Please suggest me your idea ...</p>
  
  <p><strong>UPDATE</strong>: When I use below code, just one image (last index of my image array) being saved!</p>
  
  <p>How can I save all images in array with this code?!</p>
  
  <pre><code>@Override
  protected void onPostExecute(Void result) {
     SaveImages();
     pDialog.dismiss();
     super.onPostExecute(result);
  }
  
  String fileName = null;
  
  public void SaveImages() {
      for(int i = 0; i &lt; image.length; i++) {
          Picasso.with(this).load(image[i]).into(target);
          fileName = "image-" + i + ".jpg";
      }
  }
  
  Target target = new Target() {
  
      @Override
      public void onPrepareLoad(Drawable arg0) {
      }
  
      @Override
      public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
          File file = new File(Environment.getExternalStorageDirectory().getPath() +"/" + fileName);
           try {
               file.createNewFile();
               FileOutputStream ostream = new FileOutputStream(file);
               bitmap.compress(CompressFormat.JPEG, 75, ostream);
               ostream.close();
           } catch (Exception e) {
               e.printStackTrace();
           }
      }
  
      @Override
      public void onBitmapFailed(Drawable arg0) {
      }
  };
  </code></pre>