title: changing images rapidly in java android
body: <p>I am having a problem in changing images rapidly on click. I have made an image button I want to change the image when the button is clicked and back to the previous image. I have searched a lot but cant find the solution.</p>
  
  <pre><code>public class Buttonone extends Activity {
      ImageButton btonImage;
      boolean isPressed = true;
      MediaPlayer mp;
      boolean isPlay = false;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.button_one);
  
          btonImage = (ImageButton) findViewById(R.id.btonImage);
          btonImage.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  playSound();toggleImage();
                  }
  
          });
      }
  
      private void toggleImage() {
          // TODO Auto-generated method stub
          btonImage.setImageResource(R.drawable.image2);
      }
  }
  </code></pre>
  
  <p>this is the layout xml for image button</p>
  
  <pre><code>    &lt;ImageButton
  android:id="@+id/btonImage"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:layout_alignParentLeft="true"
  android:layout_centerVertical="true"
  android:contentDescription="@null"
  android:background="#080808"   
  android:src="@drawable/image1" /&gt;
  </code></pre>