title: picasso - load image into imagebutton in adapter
body: <p>I want to load an image into a <code>ImageButton</code> in an adapter, this is sometimes not working... I have a adapter with 4 entries, and sometimes, the button image is just loaded 2 times instead of 4 times. Always only on the first creation of the adapter... After screen rotation or so, everything works fine... But on the first display, it does not work correctly...</p>
  
  <p>The adapter with 4 rows calls 2 times prepare and two times loaded on the first creation only...</p>
  
  <p>Following is my adapter's <code>getView</code>:</p>
  
  <pre><code>@Override
  public View getView(final int position, View convertView, ViewGroup parent)
  {
      if (convertView == null)
          convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_link, parent, false);
  
      convertView.setTag(R.id.tag_pos, position);
  
      ImageView iconRow = ViewHolder.get(convertView, R.id.icon);
      final ImageButton btOpen = ViewHolder.get(convertView, R.id.btOpen);
  
      // this NEVER fails
      PicassoTools.getPicasso().load(item.getIconResId()).into(iconRow);
      // this sometimes (at the first start) does not work reliable
      PicassoTools.getPicasso().load(isAutoLinked ? R.drawable.linked : R.drawable.unlinked).into(new Target()
      {
          @Override
          public void onPrepareLoad(Drawable d)
          {
              L.d(this, "BUTTON PREPARE");
          }
  
          @Override
          public void onBitmapLoaded(Bitmap b, LoadedFrom loadedFrom)
          {
              L.d(this, "BUTTON LOADED");
              btLink.setImageBitmap(b);
          }
  
          @Override
          public void onBitmapFailed(Drawable d)
          {
              L.d(this, "BUTTON FAILED");
              btLink.setImageBitmap(null);
          }
      });
  
      return convertView;
  }
  </code></pre>
  
  <p>My PicassoTools function (I have some extra functions in this class):</p>
  
  <pre><code>public static Picasso getPicasso()
  {
      if (picasso == null)
          picasso = new Picasso.Builder(MainApp.getAppContext()).memoryCache(getCache()).build();
      return picasso;
  }
  </code></pre>