title: "Cannot draw recycled bitmaps" when displaying bitmaps in Gallery attached to Adapter
body: <p>In Android 4.1 a, to me, seemingly strange error occurs in our app. In the app a custom adapter extending BaseAdapter is attached to a Gallery widget. When scrolling fast left-to-right and vice versa I get a FC with the exception message: </p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Cannot draw recycled bitmap</p>
  </blockquote>
  
  <p>Code for the getView(..) method is as follows:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder viewHolder;
  
      if (convertView == null){
          // View is not recycled. Inflate the layout.
          LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = vi.inflate(R.layout.gallery_image, parent, false);
  
          viewHolder = new ViewHolder();
          viewHolder.image = (ImageView) convertView.findViewById(R.id.gallery_image);
  
          convertView.setTag(viewHolder);
      } else {
          viewHolder = (ViewHolder)convertView.getTag();
          viewHolder.image.setImageDrawable(null);
      }
  
      imageLoader.displayImage(images.get(position).getFilename(),
              images.get(position).getUrlThumbnail(),
              viewHolder.image,
              Math.round(BitmapUtil.convertDpToPixel(400f, context)),
              Math.round(BitmapUtil.convertDpToPixel(400f, context)));
  
      return convertView;
  }
  </code></pre>
  
  <p>I guess I should null the ImageView somewhere, but I cannot get it to work correctly. ImageLoader is a (quite) simple class for loading the images - either from LruCache, disk/sdcard or fetch it remotely.</p>