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.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;

public class Main {

    public static void displayAlert4Choice(Context context, String title, String message, String positiveBtnText,
            DialogInterface.OnClickListener positionOnclick, String negativeBtnText,
            DialogInterface.OnClickListener negativeOnclick) {
        if (null == context || !(context instanceof Activity)) {
            return;
        }
        final Activity activity = (Activity) context;

        Builder builder = new AlertDialog.Builder(activity);
        builder.setCancelable(true);
        builder.setTitle(title);
        builder.setMessage(message);

        if (null == positionOnclick) {
            positionOnclick = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            };
        }
        builder.setPositiveButton(positiveBtnText, positionOnclick);

        if (null == negativeOnclick) {
            negativeOnclick = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            };
        }
        builder.setNegativeButton(negativeBtnText, negativeOnclick);

        if (!activity.isFinishing()) {
            builder.create().show();
        }
    }
}