Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;
import android.app.AlertDialog;

import android.content.Context;
import android.content.DialogInterface;

public class Main {

    public static void displayAlert(Context context, String title, String message, String buttonText) {
        if (null == context || !(context instanceof Activity)) {
            return;
        }
        final Activity activity = (Activity) context;

        AlertDialog alertDialog = new AlertDialog.Builder(activity)
                .setPositiveButton(buttonText, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).setTitle(title).setMessage(message).create();

        if (!activity.isFinishing()) {
            alertDialog.show();
        }

    }
}