I want AlertDialog with message "1" to appear on screen and after 3 seconds to dissappear then I want another AlertDialog with message "2" to appear on screen and after 3 seconds to dissappear and so on and so forth until 5. I have the following code:
[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();
}
}
But after the program's execution after some waiting I only get an AlertDialog with message "5" in it and that is. If someone think another title for my question is more appropriate he can change it.