title: CheckingButton Background Resource Id android
body: <p>I have a button</p>
  <pre><code>Button button = (Button)findViewById(R.id.button);
  button.setBakgroundResource(R.drawable.icon);
  </code></pre>
  <p>If I want to check which background resource button has, is it possible to do so? how.</p>
  <p>For example :</p>
  <pre><code>if (button.getResourceId()==R.drawable.icon)
  </code></pre>
  <p>do something with code...</p>
  <p><strong>UPDATE: THE CONDITION IS FALSE I WANT IT TO BE TRUE THE IMAGES DO NOT MATCH</strong></p>
  <pre><code>vi.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              
   
              v.findViewById(R.id.button1).setBackgroundResource(R.drawable.boutton_off);
              
              Drawable aImg = (Drawable)v.findViewById(R.id.button1).getBackground();
              Drawable bImg = v.getResources().getDrawable(R.drawable.boutton_off);
              
              if(aImg==bImg){
                  
                  System.out.println(&quot;On&quot;);
  
              }else 
                  System.out.println(&quot;off&quot;);
  
              
              
              //main.popMessage(position);
              
              
          }
          
      }); 
  </code></pre>