title: Changing the button background alternatively
body: <p>I have an android project where i need to use a switch.
  I am using a Button for this.
  I have two images one for on state and another for off state. Initially i am giving "off_image" as background of Button. When the user clicks the button the background should change to "on_image" and when again the user clicks it should change back to "off_image".</p>
  
  <p>I am using the below code but it is not working....</p>
  
  <p>Inside onClick method ---></p>
  
  <pre><code>if(button.getBackground().equals(R.drawable.off_image)
          button.setImageResource(R.drawable.on_image);
  if(button.getBackground().equals(R.drawable.on_image)
          button.setImageResource(R.drawable.off_image);
  </code></pre>
  
  <p>Please treat me as a novice and give detailed solution.</p>
  
  <p>Thank you.</p>