public void SetMainButtonChecked(boolean checked) {
   ToggleButton buttonOnOff = (ToggleButton) findViewById(R.id.buttonOnOff);
   buttonOnOff.setChecked(checked);
 }
 public void toggleConnection(View view) {
   ToggleButton tb = (ToggleButton) view;
   if (tb.isChecked()) tb.setChecked(connect(view));
   else disconnect(view);
 }