7

削除の確認メッセージボックスを追加したい。

アンドロイドでそれを行う方法は?

4

2 に答える 2

43
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;         
}

通話中

AlertDialog diaBox = AskOption();
diaBox.show();
于 2012-07-31T12:43:55.573 に答える
11

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();
于 2012-07-31T12:44:08.577 に答える