show Yes No Alert - Android android.app

Android examples for android.app:AlertDialog

Description

show Yes No Alert

Demo Code

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

public class Main{

    public static AlertDialog showYesNoAlert(Context context, boolean good,
            int titleId, int messageId,
            DialogInterface.OnClickListener positiveListener,
            DialogInterface.OnClickListener negativeListener) {
        final AlertDialog dialog = new AlertDialog.Builder(context)
                .setIcon(//w  w  w .  ja v  a  2  s. c om
                        good ? android.R.drawable.ic_menu_info_details
                                : android.R.drawable.ic_menu_close_clear_cancel)
                .setTitle(titleId).setMessage(messageId)
                .setPositiveButton(android.R.string.ok, positiveListener)
                .setNegativeButton(android.R.string.no, negativeListener)
                .create();
        dialog.show();
        return dialog;
    }

}

Related Tutorials