title: How can I write a function in separate class to display alert Box
body: <pre><code>package test;
  import test.DisplayAlert;
  
  
  public class AlertCall
  {     int j;
  
      public int dis2(String phoneNumber)
      {
        DisplayAlert ob = new DisplayAlert();     
        j=ob.dis1(AlertCall.this, phoneNumber);
        return j;
      }
    }
  </code></pre>
  
  <p><strong>The class to display the dialog box</strong></p>
  
  <pre><code>package test;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.view.View;
  import android.view.View.OnClickListener;
  
  public class DisplayAlert extends Activity implements OnClickListener
  {
      int t;
  
          public  int dis(Context activityContext, String destinationAddress)
          {
              new AlertDialog.Builder(activityContext).setTitle("SEND MESSAGE")
                 .setMessage("Are you sure you want to send this msg to no ?   "+ destinationAddress)
          .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) 
                  { 
  
                              t=0;
                    }
                  })
              .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) { 
  
                         t=1;
                 }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();
      return t;
  }
      @Override
      public void onClick(View arg0) {
          // TODO Auto-generated method stub
  
      }
      public int dis1(AlertCall alertCall, String phoneNumber) {
          // TODO Auto-generated method stub
          new AlertDialog.Builder(alertCall).setTitle("SEND MESSAGE")
             .setMessage("Are you sure you want to send this msg to no ?   "+ phoneNumber)
   .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int which) 
           { 
  
                       t=0;
             }
           })
       .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
  
                 t=1;
          }
  })
  .setIcon(android.R.drawable.ic_dialog_alert)
  .show();
  return t;
      }
  
  
  }
  </code></pre>
  
  <p>I write a class to display Alert Box and call it through separate call but its not working.When I call the function from main_Activity then it is working but if I call from another class then there is an error can anyone please suggest.</p>