Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;
import android.app.AlertDialog;

import android.content.DialogInterface;

public class Main {
    public static void yesNoMessage(final Activity activity, final String title, final String body,
            final String yesButtonLabel, final String noButtonLabel, final Runnable yesRunnable,
            final Runnable noRunnable) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {

                AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

                dialog.setTitle(title);
                dialog.setMessage(body);

                dialog.setPositiveButton(yesButtonLabel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (yesRunnable != null)
                            yesRunnable.run();
                    }
                });

                dialog.setNegativeButton(noButtonLabel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (noRunnable != null)
                            noRunnable.run();
                    }
                });

                dialog.create();
                dialog.show();
            }
        });
    }
}