title: Example on ToggleButton
body: <p>I am developing an application using a toggle button, I entered 1 or 0 in <code>EditText</code>. When button is clicked, the toggle button has to change if I enter 1 the toggle button shows <code>TOGGLE ON</code>, if I enter 0 the toggle button has to show <code>TOGGLE OFF</code>. I am unable to get toggle values when the button is clicked.</p>
  
  <p><strong>My code is:</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
    String editString="";
  
    Button btn;
    EditText ed;
    ToggleButton toggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      btn = (Button)findViewById(R.id.btn);
      ed  = (EditText)findViewById(R.id.ed);
      toggle = (ToggleButton)findViewById(R.id.toggBtn);
  
      editString = ed.getText().toString();
  
      btn.setOnClickListener(new OnClickListener() {
  
        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub
          toggle.toggle();
          if(editString.equals("1")){
  
            toggle.setTextOff("TOGGLE ON");
  
          }
          else if(editString.equals("0")){
  
            toggle.setTextOn("TOGGLE OFF");
  
          }
        }
      });
    }
  }
  </code></pre>
  
  <p><strong>xml file:</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" 
  android:orientation="vertical"&gt;
  
   &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/ed"/&gt;
   &lt;Button  android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/btn"
           android:text="Summit"/&gt;
    &lt;ToggleButton
          android:id="@+id/toggBtn"
          android:layout_below="@+id/text6"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
  
          android:gravity="center"
           /&gt;  
  </code></pre>
  
  <p></p>