title: Check state of togglebutton android
body: <p>Im new to android and I don't get the code on the developers website about this really, I just want to check if the state of the toggle button is on or off. I have the following scenario</p>
  
  <pre><code>if (isCheckedToggleButton?)
  {
      // do something         
  }
  else
  {
      // do something else
  }
  </code></pre>
  
  <p>And a method as the guide suggests </p>
  
  <pre><code>public void onToggleClicked(View view)
  {
      boolean on = ((ToggleButton)view).isChecked();
  
      if(on) {
          return;
      } else {
  
      }
  }
  </code></pre>
  
  <p>So I just want to see if the toggle button is on or off so I can decide whether to execute the code inside the if or the else. Unfortunately the method provided by the android guide is a void so it doesn't return a boolean. How can I still check the state?</p>
  
  <pre><code>        &lt;Switch
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Lift"
              android:textOff="Uit"
              android:textOn="Aan"
              android:id="@+id/switchLift" android:layout_below="@id/btnEindpunt"
              android:layout_alignLeft="@+id/btnEindpunt"/&gt;
  </code></pre>