Code example for ToggleButton

Methods: isChecked

0
        mToggleButton = (ToggleButton) findViewById(R.id.bt_toggle_button);
        mToggleButton.setChecked(mBluetoothAdapter.isEnabled());
        mToggleButton.setOnClickListener(new OnClickListener() {
            @Override 
            public void onClick(View v) {
                if (mToggleButton.isChecked()) {
                    enableBluetooth(); 
                } else { 
                    disableBluetooth(); 
                } 
            } 
        }); 
    } 
 
    private void enableBluetooth() { 
        mDisablingDialog.hide();
        mToggleButton.setEnabled(false);
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(intent, START_ENABLE_BLUETOOTH_REQUEST);
    }