我有以下代码来生成对话框。流程是这样的
测试结束 -> 用户选择保存或删除 -> 如果用户选择删除,则弹出另一个对话框要求确认删除。
该程序运行良好。但是偶尔会弹出超过 1 个删除对话框。我在某个地方犯了错误吗?
谢谢。
private void buildEndTestDialog(){
alert = new AlertDialog.Builder(getActivity());
alert.setTitle("End of Test");
alert.setCancelable(false);
alert.setNegativeButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Save
alert.dismiss();
}
});
alert.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
buildDeleteDialog();
}
});
alert.show();
}
private void buildDeleteDialog() {
alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Delete");
alert.setCancelable(false);
alert.setMessage("Are you sure you want to delete this result?");
alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//delete result
}
});
alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
alert.show();
}