Skip to main content

Alert dialog for Xamarin Android

So it occurred to me this weekend that I have been working on a project these past couple months but haven't posted any videos. Partially, this is a private project so I won't publish the code at all. The more pressing reason is I'm really learning myself as I go so it really isn't pretty.

That being said, I considered posting some code to some of my biggest road blocks but felt that might slow down my progress. I've begun helping a friend who is new to coding and realized that it is beneficial to myself to write up and be able to share/teach those coming behind me.

I will be using the label android snippets to keep my notes in regards to this Xamarin Android application. I'll add a shortcut link in the blog soon. Here's the most recent headache I had.

I will look into possibly creating a class out of some of these snippets for myself.

Alert dialog for Xamarin Android:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
       AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.SetTitle("Log out");
            alert.SetMessage("Are you sure?");
            alert.SetPositiveButton("Yes", (senderAlert, args) =>
            {
              // actions for a yes click
              // example here begins new activity
              StartActivity(typeof(LoginActivity));
            });
            alert.SetNegativeButton("No", (senderAlert, args) =>
            { 
              // action for no click
            });
            Dialog dialog = alert.Create();
            dialog.Show();

Alert Dialog for Xamarin Android
Please feel free to leave comments or contact me with any questions.

Comments