title: Changing images in ImageView with every click
body: <p>I'd appreciate it if someone could help me with my problem. 
  I am trying to change the image in an ImageView when someone clicks on it. I've put my images in an array and I am using a while loop to cycle once through all of them. </p>
  
  <p>My problem is that while the first image (image8, not in the array) shows in the view all the other (after creating the OnClickListener) do not. Actually nothing happens and I am not sure where the mistake is. Thanks in advance.</p>
  
  <p>This is the problematic code:</p>
  
  <pre><code>final int array[]=new int[5];
      array[0]= R.drawable.image6;
      array[1]= R.drawable.image4;
      array[2]= R.drawable.image9;
      array[3]= R.drawable.image4;
      array[4]= R.drawable.image5;
  
  ImageView touchView = (ImageView)findViewById(R.id.imageview);
  
  touchView.setOnTouchListener(new View.OnTouchListener()
  {
      @Override
  public boolean onTouch(View touchView, MotionEvent ev) {
      //get coordinates of touch event
          int x = (int)ev.getRawX();
          int y = (int)ev.getRawY();
  </code></pre>
  
  <p>---Code missing---</p>
  
  <pre><code>        ((ImageView)touchView).setImageResource(R.drawable.image8);
  
          touchView.setOnClickListener(new View.OnClickListener() {
          int counter = 0;
          @Override
          //Image change on every click
          public void onClick(View touchView) {
  
              while(counter&lt;5){
              ((ImageView) touchView).setImageResource(array[counter]);
                          counter++;
  
      });
  </code></pre>