title: Calling Dialog from another class
body: <p>I am beginner to android, Instead of writing code repeatedly for dialog in each activity, I just created one class which contains all the methods to show the dialog, i have given small code snippet </p>
  
  <pre><code>public class Dialogues extends Activity implements DialogueMethods {
  
  
      public void showAlertDialog(Context context, String title, String message) {
  
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
          alertDialog.setTitle(title);
          alertDialog.setMessage(message);
          alertDialog.show();
  }
  
      //this method am calling
  
      public void showAlertDialog(Context context, String title, String message, String ButtonText, boolean cancel) {
  
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
          alertDialog.setTitle(title);
          alertDialog.setMessage(message);
  
          if(cancel) {
  
              alertDialog.setNegativeButton(ButtonText, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.cancel();
                  finish();
              }
          });
          }
  
          alertDialog.show();
      }
  
  }
  </code></pre>
  
  <p>Am calling</p>
  
  <pre><code>//dialogObj is instance of the above class
  
  dialogObj.showAlertDialog(MyActivity.this, "Error", "Not Connected to Internet", "Exit", true);
  </code></pre>
  
  <p>When I run the code dialog is visible but button isn't, is this because of DialogInterace.onClickListener?, I just want to know is this good idea to do like this?, if it is then what's the correct way to do. please help me.</p>
  
  <p>thanks.</p>