create Alert with title and message - Android android.app

Android examples for android.app:AlertDialog

Description

create Alert with title and message

Demo Code

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class Main{

    public static AlertDialog createAlert(String title, String message,
            Context context) {/*  w  ww.j a v  a  2s . c o  m*/
        // Make an AlertDialog builder
        AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
        //TODO: extract string
        // Set title
        builder1.setTitle(title);
        // Set message
        builder1.setMessage(message);
        // Set cancelable
        builder1.setCancelable(true);
        // Build a new neutral button dialog
        builder1.setNeutralButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                    // On click of the neutral button
                    public void onClick(DialogInterface dialog, int id) {
                        // Cancel the dialog
                        dialog.cancel();
                    }
                });
        // Create the AlertDialog
        AlertDialog alert11 = builder1.create();
        return alert11;

    }

}

Related Tutorials