views:

34

answers:

0

I'm creating a gallery view where I'm loading images from the web. While the images are loading, I want to display an animation as a placeholder for each image. I figured this could be done using an AnimationDrawable, however, the animation won't start. The first frame of the animation loads as expected, and if I use the same in for example onWindowFoucsChanged in an activity, everything works fine.

Inside the getView method of my GalleryItemCursorAdapter (which extends SimpleCursorAdapter) I'have the following snippet:

AnimationDrawable frameAnimation = (AnimationDrawable) mContext.getResources().getDrawable(R.drawable.loading);
    holder.picture.setImageDrawable(frameAnimation);
    frameAnimation.setCallback(holder.picture);
    frameAnimation.setVisible(true, true);
    frameAnimation.start();     

holder.picture is an ImageView. I get no errors, and (very) similar code seems to work fine other places, leading me to believe this may be related to similar to the onCreate issues for animations reported elsewhere. I've tried some variations of the above code, too.

My questions:

  1. Is there an easier/better way to display a loading animation?
  2. What can I do to make the above example work (if at all possible)?