title: Is it possible to create an OnClickListener that will handle both ToggleButton and Switch
body: <p>I am working on an app that needs to be compatible with pre Android 4.0 devices.</p>
  
  <p>In the pre 4.0 layout I have to use a <code>ToggleButton</code> and in the post 4.0 am using a <code>Switch</code>. Both function the same as far as the user is concerned. When they are clicked, they should have the same behavior. </p>
  
  <p>I'm trying to write an <code>OnClickListener</code> that will work for both of them so that I'm not duplicating a lot of code. The <code>Switch</code>/<code>ToggleButtons</code> are used inside a <code>Fragment</code>, so just placing the call to the <code>onClickListener</code> in the layout won't work. </p>
  
  <p>In an effort to try it, for both the <code>Switch</code> and <code>ToggleButton</code>, I set the <code>onClickListener</code> to pushSelector, which is:</p>
  
  <pre><code>private View.OnClickListener pushSelector = new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (((ToggleButton) v).isChecked() || ((Switch) v).isChecked()) {
                  // code
              } else {
                  // code
              }
          }
      };
  </code></pre>
  
  <p>Unsurprisingly, this didn't work, but I thought I'd give it a go. </p>
  
  <p>Is it possible to have a single <code>onClickListener</code> that can handle both a <code>ToggleButton</code> and <code>Switch</code>, or will I need to set up an <code>onClickListener</code> for each one?</p>