【发布时间】:2012-11-18 16:53:16
【问题描述】:
我尝试使用布尔值作为结果创建自己的确认对话框类。我已经阅读了任何教程或建议,但结果并不如我所愿。
问题是我讨厌写长代码,我想写一个简单的代码。这个比较delphi和android在写确认对话框
德尔福:
if MessageDlg ('Message Text', mtConfirmation, [mbYes, mbNo], 0)
安卓:
boolean answer = false;
public boolean Confirm (Activity act, String Title, String ConfirmText,
CancelBtn String, String OkBtn) {
AlertDialog dialog = new AlertDialog.Builder (act). Create ();
dialog.setTitle (Title);
dialog.setMessage (ConfirmText);
dialog.setCancelable (false);
dialog.setButton (DialogInterface.BUTTON_POSITIVE, OkBtn,
new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int buttonId) {
answer = true;
}
});
dialog.setButton (DialogInterface.BUTTON_NEGATIVE, CancelBtn,
new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int buttonId) {
answer = false;
}
});
dialog.setIcon (android.R.drawable.ic_dialog_alert);
return answer;
}
问题是我能否创建一个生成确认对话的类,该类会产生一个布尔值 true 或 false,就像在 Delphi 中一样。
确认对话框,以便该类可以在课堂或其他活动中使用
【问题讨论】:
-
我已经阅读了那篇文章,但这不是我所期望的答案。我想创建一个单独的类,所有活动都可以使用更有效的编码访问确认对话框