show Close Action for Alert Dialog - Android User Interface

Android examples for User Interface:Alert Dialog

Description

show Close Action for Alert Dialog

Demo Code

import java.lang.ref.WeakReference;

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

public class Main{
    public static void showCloseAlert(final Activity ctx) {
        WeakReference<Context> weakReference = new WeakReference<Context>(
                ctx);//from w w  w .j  a v  a  2 s  .  c  om
        new AlertDialog.Builder(weakReference.get())
                .setTitle("Systems")
                .setMessage("Do you realy want to exit?")
                .setPositiveButton("Exit",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                // continue with delete
                                ctx.finish();
                                dialog.dismiss();
                            }
                        })
                .setNegativeButton("asdf",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                // continue with delete
                                dialog.dismiss();
                            }
                        })
                //                .setIcon(android.R.drawable.ic_dialog_alert)
                .show();
    }
}

Related Tutorials