Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get state of ToggleButton through handler

Tags:

I need to be able to access the state of a ToggleButton seeing is how there is no way to create methods for the specific state of a ToggleButton. So here is where I'm at so far:

ToggleButton syncSwitch = (ToggleButton)findViewById(R.id.toggleButton1); syncSwitch.setOnClickListener(new OnClickListener(){     @Override     public void onClick(View view){         Toast.makeText(getApplicationContext(), "Click!", Toast.LENGTH_SHORT).show();     } }); 

Now all I need is some type of boolean method that can tell the handler the state of the ToggleButton.

like image 474
nkcmr Avatar asked Aug 22 '11 02:08

nkcmr


People also ask

How do I get the state of toggle button?

To check current state of a toggle button programmatically we use isChecked() method. This method returns a Boolean value either true or false. If a toggle button is checked then it returns true otherwise it returns false.

What is ToggleButton How do you create it explain with example?

A toggle button allows the user to change a setting between two states. You can add a basic toggle button to your layout with the ToggleButton object. Android 4.0 (API level 14) introduces another kind of toggle button called a switch that provides a slider control, which you can add with a Switch object.

How do you use toggle button?

Android Toggle Button can be used to display checked/unchecked (On/Off) state on the button. It is beneficial if user have to change the setting between two states. It can be used to On/Off Sound, Wifi, Bluetooth etc. Since Android 4.0, there is another type of toggle button called switch that provides slider control.


1 Answers

What do you mean by 'create methods for the specific state'? You can get the state using isChecked().

like image 75
Nikolay Elenkov Avatar answered Oct 06 '22 17:10

Nikolay Elenkov