How can I trigger programmatically the following method : (without clicking/swiping the on/off toggle switch)
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
//randomness
}
I figured an alternative way would be, calling
switch1.setChecked(true);
Then doing a manual check.
There actually is a way of calling it if you refer to the class methods ;)
ToggleButton t = (ToggleButton) findViewById(R.id.myToggle); t.performClick();
See http://developer.android.com/reference/android/widget/CompoundButton.html#performClick()
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