用于删除的 Android 确认消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11740311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:40:18 来源:igfitidea点击:
Android confirmation message for delete
提问by Rakesh
I want to add a confirmation message box for delete.
我想添加一个确认消息框以进行删除。
How to do that in android?
如何在android中做到这一点?
回答by Ram kiran
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();
回答by Praveenkumar
You should do that with AlertDialog
你应该用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();