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
.
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.
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.
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.
What do you mean by 'create methods for the specific state'? You can get the state using isChecked().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With