【发布时间】:2015-12-18 11:25:07
【问题描述】:
在执行某段代码之前,我需要等待用户确认。这是我构建和显示 AlertDialog 的地方:
private bool AskForCommand()
{
bool userOK = false;
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.SetPositiveButton("Yes", (sender, args) =>
{
userOK = true;
})
.SetNegativeButton("No", (sender, args) =>
{
userOK = false;
})
.SetMessage("Send vocal command now?")
.SetTitle("System Message");
RunOnUiThread(() =>
{
dialog.Show();
});
return userOK;
}
这里是我调用方法的地方:
if (!string.IsNullOrEmpty(exactSpeech))
{
bool userOK = false;
try
{
userOK = AskForCommand();
}
catch (Exception ex)
{
//TODO: catch
}
if (cfg.InstantSendVocal || userOK)
SendCommandToBoard(exactSpeech);
}
问题是警报显示在方法“SendCommandToBoard”之后。
【问题讨论】:
标签: c# xamarin xamarin.android