Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Toggle button programmatically On & OFF in Android?

I need to make Toggle button programmatically On & OFF.

like image 224
Jai Android Avatar asked Jun 24 '11 11:06

Jai Android


2 Answers

You can use toggleButton.setChecked(true or false) method to make Toggle button programmatically On & OFF.

like image 105
Haris Hasan Avatar answered Oct 09 '22 09:10

Haris Hasan


It's so simple inside your layout file

<ToggleButton android:id="@+id/ToggleButton01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textOff="Off Stage"
    android:textOn="On Stage"/> 

and in Java

ToggleButton  tglbtn = (ToggleButton)findViewById(R.Id.ToggleButton01);

tglbtn.setChecked(false);
like image 33
neeraj t Avatar answered Oct 09 '22 07:10

neeraj t