title: Sequential animations in android studio, loop
body: <p>I am pretty new in android programing, and I am trying to make a simple game. I'd like to have 3 squares, and on start button I want to generate a few random numbers and to rotate one of the squares. I am doing that in the loop, because I number of random numbers is not fixed. </p>
  
  <pre><code>package com.example.smartpc.memorygame;
  
  import android.graphics.drawable.TransitionDrawable;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.animation.Animation;
  import android.view.animation.AnimationSet;
  import android.view.animation.RotateAnimation;
  import android.widget.Button;
  import android.widget.ImageView;
  
  import java.util.ArrayList;
  import java.util.Random;
  import java.util.Timer;
  import java.util.TimerTask;
  
  public class MemoryGame extends AppCompatActivity {
  
      ImageView imgRed;
      ImageView imgGreen;
      ImageView imgBlue;
      Button btnStart;
  
      ArrayList&lt;Integer&gt;array=new ArrayList&lt;&gt;();
      int brojac=3;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_memory_game);
  
          imgRed=(ImageView)findViewById(R.id.imgRed);
          imgGreen=(ImageView)findViewById(R.id.imgGreen);
          imgBlue=(ImageView)findViewById(R.id.imgBlue);
          btnStart=(Button)findViewById(R.id.btnStart);
  
          final RotateAnimation animation=new RotateAnimation(0f,360f, RotateAnimation.RELATIVE_TO_SELF,0.5f,
                                                              RotateAnimation.RELATIVE_TO_SELF,0.5f);
          animation.setDuration(1000);
  
          imgRed.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  imgRed.startAnimation(animation);
              }
          });
  
          imgGreen.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  imgGreen.startAnimation(animation);
              }
          });
  
          imgBlue.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  imgBlue.startAnimation(animation);
              }
          });
  
          btnStart.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  for(int i=0;i&lt;brojac;i++) {
                      Random rand = new Random();
                      int number = rand.nextInt() % 3;
                      if (number == 1) {
                          imgRed.startAnimation(animation);
                      }
                      else if (number == 2) {
                          imgGreen.startAnimation(animation);
                      }
                      else {
                          imgBlue.startAnimation(animation);
                      }
                  }
  
              }
          });
      }
  }
  </code></pre>
  
  <p>I need to wait until one animation finishes,and then I need to start another loop iteration. Does anyone have idea how to do this? Thanks!</p>