title: RecyclerView lazy loading
body: <p>I'm doing lazy loading on a RecyclerView adapter. First I fetch the image metadata (if it has any) and then let Picasso download the actual image.</p>
  
  <pre><code>public class PostHolder extends RecyclerView.ViewHolder implements Callback&lt;Photo&gt;{
      private PostImageView cover;
      private TextView content;
      private long id;
  
      public PostHolder(View itemView) {
          super(itemView);
          this.itemView.setOnClickListener(onClickListener);
          content = (TextView) itemView.findViewById(R.id.post_content);
          cover = (PostImageView) itemView.findViewById(R.id.post_image);
      }
  
      public void setPost(final Post post, int i){
          cover.unsetImage();
          this.id = post.getPhotoId();
          itemView.setTag(i);
          content.setText(post.getMessage());
  
          if("photo".equals(post.getType()) || "video".equals(post.getType()) &amp;&amp; id != 0L){
              cache.get(id, this);
          }else{
              cover.setUrl(post.getImageUrl());
          }
      }
  
      @Override
      public void result(Photo result) {
          if(result != null &amp;&amp; result.getId() == PostHolder.this.id){
              cover.setPhoto(result);
          }
      }
  }
  </code></pre>
  
  <p><code>cache.get()</code> loads my metadata from the cache, the result is returned with <code>result()</code>.<code>setPost()</code> gets called in <code>onBindViewHolder()</code>. Now I'm getting everyone's favorite viewholder issue - my <code>ImageView</code> displays a different image before switching to the correct one. I know that Picasso correctly handles this and I have a check for my own loading where i compare the holder's id to the metadata id. I've spent a few hours on this already. Internet, you are my only hope.</p>