Learn how to add an alert dialog helper class. Before you start, get a reference to the Activity that is hosting the Point of Sale user interface.
Point of Sale API

Add an Alert Dialog Helper Class

Get a reference to the Activity that is hosting the Point of Sale user interface.

Create a dialog helper class to return an AlertDialog to show call results.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.pm.PackageManager;
    import android.os.Bundle;
    import android.support.v4.app.DialogFragment;

    public class AlertDialogHelper extends DialogFragment {

      private static AlertDialog mAlertDialog;

      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
        super.onCreateDialog(savedInstanceState);
        return null;
      }

      private static Dialog getDialog(Activity activity,
        String title, String description, int resourceId) {
        if (mAlertDialog == null) {
          mAlertDialog =  new AlertDialog.Builder(activity, resourceId)
              .setTitle(title + ": " + description)
              .setPositiveButton("OK", null)
              .create();
        } else {
          mAlertDialog.setTitle(title + ":" + description);
          mAlertDialog.setOwnerActivity(activity);
        }
        return mAlertDialog;
      }

      public static void showDialog(Activity activity, String title,
         String description) {
        int resourceId = 0;
        try {
          resourceId =
              activity
                  .getPackageManager()
                  .getActivityInfo(activity.getComponentName()
                      , 0)
                  .getThemeResource();
        } catch (PackageManager.NameNotFoundException e) {
          e.printStackTrace();
        } finally {
          getDialog(
              activity,
              title,
              description,
              resourceId).show();
        }
      }
    }

If you need more assistance, contact Developer Support or ask for help in the Developer Forums.