title: AlertDialog not closing when ok button is clicked- C# xamarin
body: <p><a href="https://i.stack.imgur.com/PRkp7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PRkp7.png" alt="enter image description here"></a></p>
  
  <p>Hi all having two buttons in a listview . when i click the reject button Alertdialog will come and there i have to enter reason .. after entering the reason on OK click AlertDialog should dismiss . </p>
  
  <p>every thing is saved to DB ..but alert dialog is not closing ... instead after entering three times its closed .. i have attcahed my code below .</p>
  
  <pre><code>      btnReject.Click += delegate
              {
                  var currentItem = item;
                  Console.WriteLine(position);
  
  
                  AlertDialog.Builder alert = new AlertDialog.Builder(this.context);
                  LayoutInflater inflater = Application.Context.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
                  View viewdialog = inflater.Inflate(Resource.Layout.RejectJobsAlertDialog, null);
                  EditText getreason = viewdialog.FindViewById&lt;EditText&gt;(Resource.Id.Reason);
                  alert.SetTitle("Reject Reason ");
                  alert.SetView(viewdialog);
                  alert.SetPositiveButton("Ok", (senderAlert, args) =&gt;
                  {
  
                      item.RejectedReason = getreason.Text;
                      sharedasproxy.MobileJobdetailsUpdate(item, BASE_URL + "/xxxxx");
                      Toast.MakeText(this.context, "success!", ToastLength.Short).Show();
                      btnReject.Visibility = ViewStates.Invisible;
                      btnAccept.Visibility = ViewStates.Visible;
  
                      dialog.Cancel();
                  });
  
                  alert.SetNegativeButton("Cancel", (senderAlert, args) =&gt;
                  {
                      Toast.MakeText(this.context, "Cancelled!", ToastLength.Short).Show();
                      CloseDialog();
                  });
  
  
                  dialog = alert.Create();
  
  
                  dialog.Show();
  
  
  
  
              };
  </code></pre>