title: repeating animation with Timer
body: <p>I have two animations xml file, i use these in java class. I want my animation repeats 1000 msec. I write this code but when i run this program, animation not repeat. I use Timer in repeatAnim() function but i think this is not work in 1000msec.</p>
  
  <p>relative.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearLayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"&gt;
  &lt;TextView
      android:id="@+id/txt1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/txt1" 
     &gt;&lt;/TextView&gt;
  &lt;ImageButton
      android:id="@+id/btn2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/pic1"
      android:layout_gravity="center"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>SwitchClass.java:</p>
  
  <pre><code>public class SwitchClass extends Activity implements AnimationListener{
  
  Animation animation1;
  Animation animation2;
  boolean frontButton=true;
  ImageButton btn;
  Timer timer;
  TimerTask mTimerTask;
  Handler handler=new Handler();
  
  boolean repeat=true;
  
  @Override
  public void onCreate(Bundle savedInstanceState){
       super.onCreate(savedInstanceState);
       setContentView(R.layout.relative);
  
           animation1=AnimationUtils.loadAnimation(this, R.anim.to_middle);
       animation1.setAnimationListener(this);
       animation2=AnimationUtils.loadAnimation(this, R.anim.from_middle);
       animation2.setAnimationListener(this);
  
       btn=(ImageButton)findViewById(R.id.btn2);
       btn.setOnClickListener(onClickListener);
  
       repeatAnimation(); 
       repeatAnim();       
  }
  
  private OnClickListener onClickListener=new OnClickListener(){
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
          Intent intent=new Intent(SwitchClass.this,AnimClass.class);
          startActivity(intent);
      }
  
  };
  
  @Override
  public void onAnimationEnd(Animation animation) {
      // TODO Auto-generated method stub
      if(animation==animation1){
          if(frontButton){
              btn.setImageResource(R.drawable.pic2);
          }
          else{
              btn.setImageResource(R.drawable.pic1);
          }
          btn.clearAnimation();
          btn.setAnimation(animation2);
          btn.startAnimation(animation2);
      }
      else{
          frontButton=!frontButton;
          btn.setEnabled(true);
      }
  }
  
  @Override
  public void onAnimationRepeat(Animation animation) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void onAnimationStart(Animation animation) {
      // TODO Auto-generated method stub
  
  }
  
  public void repeatAnim(){
      timer=new Timer();
      mTimerTask=new TimerTask(){
          public void run(){
              handler.post(new Runnable(){
                  public void run(){
                      repeatAnimation();
  
                  }
              });
          }
      };
      timer.schedule(mTimerTask, 1000);
  }
  public void repeatAnimation(){
      btn.setEnabled(false);
      btn.clearAnimation();
      btn.setAnimation(animation1);
      btn.startAnimation(animation1);
  }
  }
  </code></pre>
  
  <p>Thanks for advise.Cheers</p>