title: Picasso and Adapter with viewHolder
body: <p>I have problem with working with Picasso. I can't access viewHolder from Target class. And there is a problem with saving downloaded pictures. Can somebody help me???? Please.</p>
  
  <p>here is a code of adapter: </p>
  
  <pre><code>   public AsanasAdapter(List&lt;Asana&gt; asanaList, Context mContext){
  
          this.mContext = mContext;
          this.asanaList = asanaList;
          this.layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
  
  
      @Override
      public int getCount() {
          return asanaList.size();
      }
  
      @Override
      public Asana getItem(int position) {
          return asanaList.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return 0;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
  
           ViewHolder viewHolder =null;
  
  
          if(convertView==null){
  
              viewHolder = new ViewHolder();
              convertView = layoutInflater.inflate(R.layout.asanas_item, null);
              viewHolder.asanaName = (TextView) convertView.findViewById(R.id.asana_name);
              viewHolder.asanaDesc = (TextView) convertView.findViewById(R.id.asana_desc);
              viewHolder.asanaImg = (ImageView) convertView.findViewById(R.id.asana_img);
              convertView.setTag(viewHolder);
  
          }
          else
          {
              viewHolder = (ViewHolder) convertView.getTag();
          }
  
          String name = getItem(position).getName();
          String desc = getItem(position).getDescShort();
  
          viewHolder.asanaDesc.setText(desc);
          viewHolder.asanaName.setText(name);
  
          final File imgFile = new File(Environment.getDataDirectory()+"/"+getItem(position).getId()+".png");
  
          if(imgFile.exists()){
  
              Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
  
              viewHolder.asanaImg.setImageBitmap(myBitmap);
  
          }
          else if (isNetworkConnected()) {
  
              Log.d("MYLOGGGGGGGG", MYurl.BASE_URL + "/" + getItem(position).getImgThumb() + "");
              final ViewHolder finalViewHolder = viewHolder;
              Picasso.with(mContext)
                      .load(MYurl.BASE_URL + "/" + getItem(position).getImgThumb())
                      .into(new Target() {
                          @Override
                          public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                              viewHolder
                              File fPath = Environment.getDataDirectory();
                              File file = new File(fPath, getItem(position)+".png");
                              if (!file.exists()) {
                                  try {
                                      file.mkdirs();
                                      file.createNewFile();
                                  } catch (IOException e) {
                                      e.printStackTrace();
                                  }
                              }
  
                              FileOutputStream out = null;
                              try{
                                  out = new FileOutputStream(file);
                                  bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
                              }
                              catch (Exception e){
                                  e.printStackTrace();
                              }
                              finally {
                                  try{
                                      if (out != null){
                                          out.close();
                                      }
                                  }
                                  catch (IOException e){
                                      e.printStackTrace();
                                  }
                              }
                          }
  
                          @Override
                          public void onBitmapFailed(Drawable errorDrawable) {
  
                          }
  
                          @Override
                          public void onPrepareLoad(Drawable placeHolderDrawable) {
  
                          }
                      });
  
          }
          else{
           //   viewHolder.asanaImg.setImageBitmap();
  
  
          }
  
  
          return convertView;
      }
  
  
  
      public boolean isNetworkConnected() {
          ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo ni = cm.getActiveNetworkInfo();
          if (ni == null) {
              // There are no active networks.
              return false;
          } else
              return true;
      }
  
      static class ViewHolder {
          ImageView asanaImg;
          TextView asanaName;
          TextView asanaDesc;
  
  
      }
  
  
  
  }
  </code></pre>