Use of ToggleButton widget in android

ToggleButton is used for making on/off function

.

Here is its Program-

public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
    EditText e;
    ToggleButton t;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        e=(EditText)findViewById(R.id.editText);
        t=(ToggleButton)findViewById(R.id.toggleButton4);
        t.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        e.setText("" + isChecked);
    }
}

 

Leave a Reply