Switch a; // define your switch   a.setOnClickListener(      new View.OnClickListener() {          @Override          public void onClick(View view) {                b.setChecked(!b.isChecked);          }       }); 

Read more of this post