2

I am using sequence for animation in my project. I have set onClickListener to that image where I put animation sequences. now when first time I run the code, and click on image, it start run animation correctly but then it never run again on click. I have to again run the code. So how I can run animation sequences more than one time? I have put my codebelow to start animation sequence.

image.setOnClickListener(new OnClickListener() {

      @Override           
      public void onClick(View v) {

          // TODO Auto-generated method stub

          animation_door = (AnimationDrawable) image.getBackground();
          animation_door.start();             

} });

Chirag_CID
  • 2,224
  • 1
  • 24
  • 33

2 Answers2

2

Well, before clicking your button again you have to stop the animation also, so you can try it like this,

 image.setOnClickListener(new OnClickListener() {

            @Override           
            public void onClick(View v) {

                animation_door = (AnimationDrawable) image.getBackground();
                animation_door.stop();
                animation_door.start();         
              }
          });
halfer
  • 19,824
  • 17
  • 99
  • 186
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

Is your animation set as a oneShot? It's most likely in the end state and you just need to hint it back to the start state.

AnimationDrawable door = (AnimationDrawable) image.getBackground();
door.setOneShot(false);
door.start();

Keep in mind this will most likely lead to a looping animation, which you probably don't want. You could consider using an Animation Set instead since you'll have a bit more control over the animation itself.

csaunders
  • 1,712
  • 1
  • 15
  • 20
  • Thanks,...but I want oneshot animation on click, therefore I have set oneshot in xml. Is there any way to make animation clickable,means on each click it should start animation??..thanks in advance. – Chirag_CID Sep 07 '11 at 05:06