我希望带有消息“1”的 AlertDialog 出现在屏幕上,并在 3 秒后消失,然后我希望另一个带有消息“2”的 AlertDialog 出现在屏幕上,并在 3 秒后消失,依此类推,直到 5。我有以下代码:
[Activity(Label = "TestAlertDialogBuilder", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
for (int i=0; i <=5 ; i++)
{
//making the program stop so I can see the alert showing and dissappearing
System.Threading.Thread.Sleep(3000);
ShowAlert(i);
}
}
Dialog dialog;
public void ShowAlert(int i)
{
if (dialog != null)
{
dialog.Cancel();
}
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.SetMessage(i.ToString());
dialog = alertDialog.Create();
dialog.Show();
}
}
但是在等待一段时间后程序执行后,我只得到一个带有消息“5”的AlertDialog,就是这样。如果有人认为我的问题的另一个标题更合适,他可以更改它。