show Alert Box - Android User Interface

Android examples for User Interface:Alert Dialog

Description

show Alert Box

Demo Code


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

public class Main {
    public static AlertDialog alertDialog;

    public static void showAlertBox(final Activity activity,
            final String title, String Msg) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                activity);//from  www  .  j a v a  2 s.c o  m

        // set title
        alertDialogBuilder.setTitle(title);

        // set dialog message
        alertDialogBuilder
                .setMessage(Msg)
                .setCancelable(false)
                .setPositiveButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                if (title.contains("No Connection Found"))
                                    activity.finish();
                                alertDialog.dismiss();
                            }
                        });

        // create alert dialog
        alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();
    }
}

Related Tutorials