title: Android Switch setOnCheckedChangeListener method to pass Object by applying DRY principle
body: <pre><code>toggle1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  
              try
              {
                  String msg ="";
                  if (isChecked) {
                      // The toggle is enabled
  
                      //msg = "Hello " + String.valueOf(!isChecked);
                      msg = "1";
  
  
                  } else {
                      // The toggle is disabled
                      //msg = "Hello " + String.valueOf(!isChecked);
                      msg = "1";
                  }
                  msg += "\n";
                  outputStream.write(msg.getBytes());
  
              }
              catch (IOException ex) { }
              catch (NullPointerException ex) { }
  
  
  
          }
      });
  </code></pre>
  
  <p>Please consider the above code. Now I have 1 Switch this code snippet is good enough. However, if I have 4 Switchs so 4 times repeat this code snippet. So this is duplicate. 
  Here for each switch toggl1 ->msg = "1";  for toggl2 ->msg = "2"; <strong>Just this change each place.</strong> </p>
  
  <p>How I can pass  object to <strong>setOnCheckedChangeListener</strong> so that I can obey DRY principle ? </p>