title: I want to set animation on ImageView
body: <p>i want to make a toss app ..it is spining all time and will not stop to show a head or tail..i want that when i click on the coin then it should spin for 2 3 seconds and then stops to show head or tail at random selection...but it is continuously spinning.
  Here is the code...</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  ImageView Coin;
  @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Coin=(ImageView) findViewById(R.id.ImgViewcoin);
      Coin.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Animation animation = new AlphaAnimation(1, 0);
              animation.setInterpolator(new DecelerateInterpolator());
              animation.setDuration(3000);
              Coin.startAnimation(animation);
              animation.setAnimationListener(new Animation.AnimationListener() {
                  @Override
                  public void onAnimationStart(Animation animation) {
                      final int[] photos = {R.drawable.heads, R.drawable.tails};
                      final ImageView image = (ImageView) findViewById(R.id.ImgViewcoin);
                      final Random ran = new Random();
                      int i = ran.nextInt(photos.length);
                      image.setImageResource(photos[i]);
                      image.setOnClickListener(new View.OnClickListener() {
                                                   public void onClick(View v) {
                                                       int k = ran.nextInt(photos.length);
                                                       image.setImageResource(photos[k]);
                                                   }
                                               }
                      );
                  }
                  @Override
                  public void onAnimationEnd(Animation animation) {
                  }
                  @Override
                  public void onAnimationRepeat(Animation animation) {
                  }
              });
              Coin.startAnimation(animation);
           }
        });
    }
    }
  </code></pre>