title: ImageButton Android switch bg image
body: <p>Can anyone tell me why this is not working?  I have no errors at all but simply doesnt work.</p>
  
  <p>This actually used to work fine until I added the ScreenSwipe, now I cant figure out whats wrong.</p>
  
  <p>Thanks</p>
  
  <pre><code>package com.sample.sample
  
  import android.app.Fragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageButton;
  
  public class PageOneFragment extends Fragment {
  
  ImageButton btn1;
  static int i = 0;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
  ViewGroup rootView = (ViewGroup) inflater.inflate(
          R.layout.page1_layout, container, false);
  btn1 = (ImageButton) rootView.findViewById(R.id.m1_btn);
  return rootView;
  }
  
  public void setupPlayPauseButton1(View view) {
      btn1 = (ImageButton) view.findViewById(R.id.m1_btn);
  
      btn1.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              i +=1;
              if (i % 2 == 0) {
                  btn1.setImageResource(R.drawable.pause);
              } else {
                  btn1.setImageResource(R.drawable.play);
  
              }
          }
      });
  }
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Is this right?</p>
  
  <pre><code>package com.wepromoteme.brapp;
  
  import android.app.Fragment;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageButton;
  
  public class PageOneFragment extends Fragment {
  
  ImageButton btn1;
  int i = 0;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
  ViewGroup rootView = (ViewGroup) inflater.inflate(
          R.layout.page1_layout, container, false);
  btn1 = (ImageButton) rootView.findViewById(R.id.m1_btn);
  
  
  setupPlayPauseButton1(rootView);
  
  return rootView;
  
  }
  
  private void setupPlayPauseButton1(View view) {
      btn1 = (ImageButton) view.findViewById(R.id.m1_btn);
  
      btn1.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              // TODO Auto-generated method stub
              i +=1;
              if (i % 2 == 0) {
                  btn1.setImageResource(R.drawable.pause);
              } else {
                  btn1.setImageResource(R.drawable.play);
  
              }
          }   
      });
  }
  }
  </code></pre>