我尝试使用 C#(VS2010 + dot42/mono)“开发”一个 Android 应用程序,该应用程序显示大量 od 消息,获取用户输入并创建 AlertDialogs。问题是: 1. 你知道如何捕捉Android AlertDialog(s) 返回的OnCancel事件吗?2.如何检测到底是哪个AlertDialog发送的?
更清楚地说,我试图让AlertDialog.Builder SetOnCancelListener(IDialogInterface_IOnCancelListener onCancelListener)工作。
我创建了一个显示简单消息框的方法,我尝试以某种方式捕获(但到目前为止都是错误的)onCancel事件。请看下文。你能帮助我吗?
private void button2_OnClick(object sender, EventArgs eventArgs)
{
AlertDialog.Builder a_builder = new AlertDialog.Builder(this);
a_builder.SetMessage("Is this all?");
a_builder.SetTitle("Question");
a_builder.SetPositiveButton("Yes", OnMsgClick_Result2 );
a_builder.SetNegativeButton("Not yet" OnMsgClick_Result2);
a_builder.SetCancelable(true);
a_builder.SetOnCancelListener(
new IDialogInterface_IOnCancelListener(
new IDialogInterface_IOnClickListener(IDialogInterface dialog) {
switch (dialog.which) //<--------- ???
{
case _dialogA:
text1.settext("DialogA was canceled");
break;
case _dialogB:
text1.settext("DialogB was canceled");
break;
default:
text1.settext("Nothing has been canceled");
break;
}
})
); //<--- ??? ERROR HERE of course
a_builder.Create().Show();
}