title: Android BaseAdapter with Animation to ImageView
body: <p>I have created Base Adapter and applying animation to image-view which is part of that custom layout after every 3 second. Each row is having array of images so I'm trying to fade-out current image and fad-in new one.I have created handler with runnable timer in activity which is calling adapter.notifyDataSetChanged() after every 3 second. Without applying animation my adapter would be like as below :</p>
  
  <pre><code>public class FerrariAdapter extends BaseAdapter {
  
  /*
   * Variable Declaration Part
   */
  
  private Context mContext;
  private ArrayList&lt;String&gt; mTitle, mOwner, mDate;
  private HashMap&lt;String, ArrayList&lt;String&gt;&gt; mImages;
  private HashMap&lt;Integer, Integer&gt; mLastImagePosition;
  private ViewHolder mHolder;
  private boolean is_animation = false;
  private Animation mFadeIn, mFadeOut;
  
  /* Constructor that initialize variables getting from activity */
  
  public FerrariAdapter(Context mContext, ArrayList&lt;String&gt; mTitle,
          ArrayList&lt;String&gt; mOwner, ArrayList&lt;String&gt; mDate,
          HashMap&lt;String, ArrayList&lt;String&gt;&gt; mImages,
          HashMap&lt;Integer, Integer&gt; mLastImagePosition) {
  
      this.mContext = mContext;
      this.mTitle = mTitle;
      this.mOwner = mOwner;
      this.mDate = mDate;
      this.mImages = mImages;
      this.mLastImagePosition = mLastImagePosition;
      mFadeOut = AnimationUtils.loadAnimation(mContext, R.anim.anim_fadeout);
      mFadeIn = AnimationUtils.loadAnimation(mContext, R.anim.anim_fadein);
  
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return mTitle.size();
  }
  
  @Override
  public Object getItem(int position) {
      // TODO Auto-generated method stub
      return mTitle.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      View mView = convertView;
      if (mView == null) {
  
          /*
           * Inflating custom layout and getting components IDs to set each
           * row of ListView
           */
  
          mView = LayoutInflater.from(mContext).inflate(R.layout.car_tile,
                  null);
          mHolder = new ViewHolder();
          mHolder.mTitleHolder = (TextView) mView
                  .findViewById(R.id.titleHolder);
          mHolder.mOwnerHolder = (TextView) mView
                  .findViewById(R.id.OwnerHolder);
          mHolder.mDateHolder = (TextView) mView
                  .findViewById(R.id.dateHolder);
          mHolder.mImageHolder = (ImageView) mView
                  .findViewById(R.id.imageHolder);
  
          mView.setTag(mHolder);
      } else {
          mHolder = (ViewHolder) mView.getTag();
      }
  
      /* Set Value to each row */
  
      mHolder.mTitleHolder.setText(mTitle.get(position));
      mHolder.mOwnerHolder.setText(mOwner.get(position));
      mHolder.mDateHolder.setText(Utils.millisToDate(
              Long.parseLong(mDate.get(position)), "dd MMM yyyy HH:mm"));
  
      mHolder.mImageHolder.setImageBitmap(getImagefromHashmap(position));
      /*mFadeOut.setAnimationListener(new AnimationListener() {
  
          @Override
          public void onAnimationStart(Animation animation) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onAnimationRepeat(Animation animation) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onAnimationEnd(Animation animation) {
              // TODO Auto-generated method stub
  
          }
      });
      mHolder.mImageHolder.setAnimation(mFadeOut);*/
  
      return mView;
  }
  
  /*
   * This class is used to hold position of each component so it shouln't be
   * repeat again and again
   */
  
  class ViewHolder {
  
      ImageView mImageHolder;
      TextView mTitleHolder, mOwnerHolder, mDateHolder;
  
  }
  
  private Bitmap getImagefromHashmap(int position) {
  
      Bitmap mBitmap = null;
      ArrayList&lt;String&gt; mImagesList = mImages.get(mTitle.get(position));
      int mLastImagePostion = mLastImagePosition.get(position);
  
      if (mImagesList.size() - 1 &gt; mLastImagePostion) {
  
          mLastImagePostion++;
          mLastImagePosition.put(position, mLastImagePostion);
  
      } else {
  
          mLastImagePostion = 0;
          mLastImagePosition.put(position, mLastImagePostion);
  
      }
  
      String mImageName = mImagesList.get(mLastImagePostion);
      // Get the AssetManager
      AssetManager manager = mContext.getAssets();
  
      // Read a Bitmap from Assets
      try {
          InputStream mOpen = manager.open(mImageName);
          mBitmap = BitmapFactory.decodeStream(mOpen);
  
      } catch (Exception e) {
  
      }
  
      return Utils.resize(mBitmap,
              (int) (Utils.getDeviceWidth(mContext) / 2.5),
              Utils.getDeviceHeight(mContext) / 5);
  
  }
  }
  </code></pre>
  
  <p>And it is working well by changing image to imageview with each row. Now when I'm going to apply animation on getview(), Only last row is getting affected. So I think getView() is called before completion of animation for the each row. While applying animation :</p>
  
  <pre><code>public class FerrariAdapter extends BaseAdapter {
  
  /*
   * Variable Declaration Part
   */
  
  private Context mContext;
  private ArrayList&lt;String&gt; mTitle, mOwner, mDate;
  private HashMap&lt;String, ArrayList&lt;String&gt;&gt; mImages;
  private HashMap&lt;Integer, Integer&gt; mLastImagePosition;
  private ViewHolder mHolder;
  private boolean is_animation = false;
  private Animation mFadeIn, mFadeOut;
  
  /* Constructor that initialize variables getting from activity */
  
  public FerrariAdapter(Context mContext, ArrayList&lt;String&gt; mTitle,
          ArrayList&lt;String&gt; mOwner, ArrayList&lt;String&gt; mDate,
          HashMap&lt;String, ArrayList&lt;String&gt;&gt; mImages,
          HashMap&lt;Integer, Integer&gt; mLastImagePosition) {
  
      this.mContext = mContext;
      this.mTitle = mTitle;
      this.mOwner = mOwner;
      this.mDate = mDate;
      this.mImages = mImages;
      this.mLastImagePosition = mLastImagePosition;
      mFadeOut = AnimationUtils.loadAnimation(mContext, R.anim.anim_fadeout);
      mFadeIn = AnimationUtils.loadAnimation(mContext, R.anim.anim_fadein);
  
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return mTitle.size();
  }
  
  @Override
  public Object getItem(int position) {
      // TODO Auto-generated method stub
      return mTitle.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      View mView = convertView;
      if (mView == null) {
  
          /*
           * Inflating custom layout and getting components IDs to set each
           * row of ListView
           */
  
          mView = LayoutInflater.from(mContext).inflate(R.layout.car_tile,
                  null);
          mHolder = new ViewHolder();
          mHolder.mTitleHolder = (TextView) mView
                  .findViewById(R.id.titleHolder);
          mHolder.mOwnerHolder = (TextView) mView
                  .findViewById(R.id.OwnerHolder);
          mHolder.mDateHolder = (TextView) mView
                  .findViewById(R.id.dateHolder);
          mHolder.mImageHolder = (ImageView) mView
                  .findViewById(R.id.imageHolder);
  
          mView.setTag(mHolder);
      } else {
          mHolder = (ViewHolder) mView.getTag();
      }
  
      /* Set Value to each row */
  
      mHolder.mTitleHolder.setText(mTitle.get(position));
      mHolder.mOwnerHolder.setText(mOwner.get(position));
      mHolder.mDateHolder.setText(Utils.millisToDate(
              Long.parseLong(mDate.get(position)), "dd MMM yyyy HH:mm"));
  
  
      mFadeOut.setAnimationListener(new AnimationListener() {
  
          @Override
          public void onAnimationStart(Animation animation) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onAnimationRepeat(Animation animation) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void onAnimationEnd(Animation animation) {
              // TODO Auto-generated method stub
  
              mHolder.mImageHolder.setImageBitmap(getImagefromHashmap(position));
          }
      });
      mHolder.mImageHolder.setAnimation(mFadeOut);
  
      return mView;
  }
  
  /*
   * This class is used to hold position of each component so it shouln't be
   * repeat again and again
   */
  
  class ViewHolder {
  
      ImageView mImageHolder;
      TextView mTitleHolder, mOwnerHolder, mDateHolder;
  
  }
  
  private Bitmap getImagefromHashmap(int position) {
  
      Bitmap mBitmap = null;
      ArrayList&lt;String&gt; mImagesList = mImages.get(mTitle.get(position));
      int mLastImagePostion = mLastImagePosition.get(position);
  
      if (mImagesList.size() - 1 &gt; mLastImagePostion) {
  
          mLastImagePostion++;
          mLastImagePosition.put(position, mLastImagePostion);
  
      } else {
  
          mLastImagePostion = 0;
          mLastImagePosition.put(position, mLastImagePostion);
  
      }
  
      String mImageName = mImagesList.get(mLastImagePostion);
      // Get the AssetManager
      AssetManager manager = mContext.getAssets();
  
      // Read a Bitmap from Assets
      try {
          InputStream mOpen = manager.open(mImageName);
          mBitmap = BitmapFactory.decodeStream(mOpen);
  
      } catch (Exception e) {
  
      }
  
      return Utils.resize(mBitmap,
              (int) (Utils.getDeviceWidth(mContext) / 2.5),
              Utils.getDeviceHeight(mContext) / 5);
  
  }
  }
  </code></pre>
  
  <p>So how to handle this situation or how to force getView() to be called after completion of animation for each row?</p>
  
  <p>Thanks,</p>