Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android confirmation message for delete [closed]

I want to add a confirmation message box for delete.

How to do that in android?

like image 290
Rakesh Avatar asked Jul 31 '12 12:07

Rakesh


2 Answers

private AlertDialog AskOption()
{
    AlertDialog myQuittingDialogBox = new AlertDialog.Builder(this) 
        // set message, title, and icon
        .setTitle("Delete") 
        .setMessage("Do you want to Delete") 
        .setIcon(R.drawable.delete)

        .setPositiveButton("Delete", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) { 
                //your deleting code
                dialog.dismiss();
            }   

        })
        .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();

            }
        })
        .create();

    return myQuittingDialogBox;         
}

Calling

AlertDialog diaBox = AskOption();
diaBox.show();
like image 54
Ram kiran Pachigolla Avatar answered Sep 19 '22 06:09

Ram kiran Pachigolla


You should do that with AlertDialog

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which){
        case DialogInterface.BUTTON_POSITIVE:
            //Do your Yes progress
            break;

        case DialogInterface.BUTTON_NEGATIVE:
            //Do your No progress
            break;
        }
    }
};
AlertDialog.Builder ab = new AlertDialog.Builder(this);
    ab.setMessage("Are you sure to delete?").setPositiveButton("Yes", dialogClickListener)
        .setNegativeButton("No", dialogClickListener).show();
like image 30
Praveenkumar Avatar answered Sep 21 '22 06:09

Praveenkumar