title: Getting return value from onClickListener of Android
body: <p>Can I set variable into context like session in web development?</p>
  
  <p>Here is my code to in which I am developing an confirmation box as soon as the Android application get started:</p>
  
  <pre><code>package com.example.alertboxandloadingwidgets;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.view.Menu;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Boolean result = showConfirmationBox("Are you sure you want to do this",
          this);
      }
      public Boolean showConfirmationBox(String messageToShow, final Context context) {
          // prepare the alert box
          AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
          // set the message to display
          alertbox.setMessage(messageToShow);
          // set a positive/yes button and create a listener
          alertbox.setPositiveButton("Yes",
          new DialogInterface.OnClickListener() {
              // do something when the button is clicked
              public void onClick(DialogInterface arg0, int arg1) {
                  Toast.makeText(context,
                      "'Yes' button clicked", Toast.LENGTH_SHORT)
                      .show();
              }
          });
          // set a negative/no button and create a listener
          alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {
              // do something when the button is clicked
              public void onClick(DialogInterface arg0, int arg1) {
                  Toast.makeText(context, "'No' button clicked",
                  Toast.LENGTH_SHORT).show();
              }
          });
          // display box
          alertbox.show();
      }
  }
  </code></pre>
  
  <p>But I want that if the <code>yes</code> button is clicked then it has to return <code>true</code> and if <code>no</code> button is clicked then it has to return <code>false</code>. </p>
  
  <p>But I am not able to do so because return type of <code>onClickListener</code> is void.</p>
  
  <h2>Update</h2>
  
  <p>But the problem is that I have make it generic means This method I have to write in a CommonUtilities Class From where any of the activity can use this method. So I have to set or reset the value the result parameter from where I am calling this method.</p>