title: how to play a gif animation image on imagebutton click
body: <p>I have a imageButton with some pic as its src. I want to switch from that pic to an animated .gif file when i click on image button.
  i am using android studio. 
  I tried to use normal method onCLick="" in layout but it's not working. I am getting an still image
  everytime normal static image is coming up.</p>
  
  <p><strong>newon is gif image</strong></p>
  
  <pre><code>public void buttonClick3(View v) {
      SharedPreferences sharedPreferences = getSharedPreferences("NAME", Context.MODE_PRIVATE);
      Boolean e = sharedPreferences.getBoolean("clicked3", false);
      if (!e) {
          aButton3.setImageResource(R.drawable.newon);
          toggleSound.start();
          sharedPreferences = getSharedPreferences("NAME", Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor.putBoolean("clicked3", true);
          editor.commit();
      }
      if(e){
          aButton3.setImageResource(R.drawable.newoff);
          sharedPreferences = getSharedPreferences("NAME", Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor = sharedPreferences.edit();
          editor.putBoolean("clicked3", false);
          editor.commit();
          toggleSound.start();
  
      }
  }
  </code></pre>