title: ClassCastException: AbsListView$LayoutParams cannot be cast to Gallery$LayoutParams
body: <p>I'm trying to develop an Android 3.1 tablet application.</p>
  
  <p>This app will have a lot of images, and I have followed <a href="http://developer.android.com/training/displaying-bitmaps/process-bitmap.html">Processing Bitmaps Off the UI Thread</a> tutorial, but I've done something wrong because I get:</p>
  
  <p><strong>java.lang.ClassCastException</strong>: android.widget.AbsListView$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams</p>
  
  <p>This is my code:</p>
  
  <p><strong>I set up Gallery on an Activity</strong><br/></p>
  
  <pre><code>mFactGallery = (Gallery)mView.findViewById(R.id.factGallery);
  mFactGallery.setAdapter(new ImageGalleryAdapter(mActivity, ImageView.ScaleType.FIT_END, 180, 90));
  </code></pre>
  
  <p><strong>ImageGalleryAdapter.java</strong></p>
  
  <pre><code>public class ImageGalleryAdapter extends BaseAdapter
  {
      private ArrayList&lt;String&gt; mImagesPath;
      private Context mContext;
      private int mWidth;
      private int mHeight;
  
      public ArrayList&lt;String&gt; getmImagesPath()
      {
          return mImagesPath;
      }
  
      public void setmImagesPath(ArrayList&lt;String&gt; mImagesPath)
      {
          this.mImagesPath = mImagesPath;
      }
  
      public void addImage(String imagePath)
      {
          mImagesPath.add(imagePath);
      }
  
      public ImageGalleryAdapter(Context context, ImageView.ScaleType scaleType, int width, int height)
      {
          mContext = context;
          mWidth = width;
          mHeight = height;
          mScaleType = scaleType;
  
          mImagesPath = new ArrayList&lt;String&gt;();
      }
  
      @Override
      public int getCount()
      {
          return mImagesPath.size();
      }
  
      @Override
      public Object getItem(int position)
      {
          return position;
      }
  
      @Override
      public long getItemId(int position)
      {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent)
      {
          // Get a View to display image data                     
          ImageView imageView;
          // if it's not recycled, initialize some attributes
          if (convertView == null)
          {
              imageView = new ImageView(mContext);
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setLayoutParams(new GridView.LayoutParams(
                      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
          }
          else
          {
              imageView = (ImageView) convertView;
              // Recicla el Bitmap.
              Bitmap bm = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
              if (bm != null)
                  bm.recycle();
          }
  
          String filePath = mImagesPath.get(position);
          if (BitmapTools.cancelPotentialWork(filePath, imageView))
          {
              String[] params = {filePath, Integer.toString(mWidth), Integer.toString(mHeight)};
              final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
              final AsyncDrawable asyncDrawable =
                      new AsyncDrawable(mContext.getResources(), filePath, task);
              imageView.setImageDrawable(asyncDrawable);
              task.execute(params);
          }
  
          return imageView;
      }
  }
  </code></pre>
  
  <p><strong>BitmapWorkerTask.java</strong><br/></p>
  
  <pre><code>public class BitmapWorkerTask extends AsyncTask&lt;String, Void, Bitmap&gt;
  {
      private final WeakReference&lt;ImageView&gt; imageViewReference;
      public String imgPath = "";
  
      public BitmapWorkerTask(ImageView imageView) {
          // Use a WeakReference to ensure the ImageView can be garbage collected
          imageViewReference = new WeakReference&lt;ImageView&gt;(imageView);
      }
  
      // Decode image in background.
      @Override
      protected Bitmap doInBackground(String... params)
      {
          imgPath = params[0];
          int width = Integer.valueOf(params[1]).intValue();
          int height = Integer.valueOf(params[2]).intValue();
          return BitmapTools.decodeSampledBitmapFromDisk(imgPath, width, height);
      }
  
      // Once complete, see if ImageView is still around and set bitmap.
      @Override
      protected void onPostExecute(Bitmap bitmap)
      {
          if (isCancelled())
          {
              bitmap = null;
          }
  
          if (imageViewReference != null &amp;&amp; bitmap != null)
          {
              final ImageView imageView = imageViewReference.get();
              final BitmapWorkerTask bitmapWorkerTask =
                      BitmapTools.getBitmapWorkerTask(imageView);
              if (this == bitmapWorkerTask &amp;&amp; imageView != null)
              {
                  imageView.setImageBitmap(bitmap);
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>AsyncDrawable.java</strong><br/></p>
  
  <pre><code>public class AsyncDrawable extends BitmapDrawable
  {
      private final WeakReference&lt;BitmapWorkerTask&gt; bitmapWorkerTaskReference;
  
      public AsyncDrawable(Resources res, String filepath,
              BitmapWorkerTask bitmapWorkerTask)
      {
          super(res, filepath);
          bitmapWorkerTaskReference =
              new WeakReference&lt;BitmapWorkerTask&gt;(bitmapWorkerTask);
      }
  
      public BitmapWorkerTask getBitmapWorkerTask()
      {
          return bitmapWorkerTaskReference.get();
      }
  }
  </code></pre>
  
  <p><strong>What am I doing wrong?</strong></p>