get state of ToggleButton through handler

nkcmr picture nkcmr · Aug 22, 2011 · Viewed 36.5k times · Source

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.

Answer

Nikolay Elenkov picture Nikolay Elenkov · Aug 22, 2011

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