title: Put check box listener into button listener
body: <p>I have a save <code>button</code> and <code>checkbox</code> in <strong>Activtiy A</strong>.</p>
  
  <p>When save <code>button</code> is clicked, it will display the <code>checkbox</code> text if <code>checkbox</code> is <strong>checked</strong>. </p>
  
  <pre><code>         save.setOnClickListener(new View.OnClickListener() { // if save button clicked
  
                           @Override
                           public void onClick(View v) {
                                   if(checkbox.isChecked()) {
                                       returnIntent.putExtra("outstation", checkbox.getText().toString());
                                       Toast.makeText(getApplicationContext(),checkbox.getText().toString(),Toast.LENGTH_LONG).show();
                                   }
                                }
                            });
  
       public void addListenerOnChk() // for checkbox
          {
              checkbox=(CheckBox)findViewById(R.id.checkBox);
  
              checkbox.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                          if(((CheckBox)v).isChecked())
                          {
                                // Toast.makeText(getApplicationContext(),checkbox.getText().toString(),Toast.LENGTH_LONG).show();
                          }
                      }
  
                  });
              }
  </code></pre>
  
  <p>The above code works fine but it looked weird. I define <code>addListenerOnChk()</code> in <code>OnCreate</code> method. How can I put the check box inside save <code>onClick</code> instead of create two seperate <code>OnClick</code> ? (One is save button and another is checkbox) </p>