Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Unable to add window — token null is not for an application AlertBuilder

$
0
0

I am trying to use an AlertBox in which There will be a title, a message, input field, cancel and okay . I have done some googling and find some code but when I am trying to implement that code I am getting the error on alertdialog.Show();
Unable to add window — token null is not for an application AlertBuilder

here is a snippet of code--

    public async Task InputClickedAsync()
         {
             string Number = "";
             try
             {
            EditText et = new EditText(_context)
            {
                InputType = Android.Text.InputTypes.NumberFlagDecimal | Android.Text.InputTypes.ClassNumber
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(_context);
            builder.SetTitle("Enter Quantity");
            builder.SetPositiveButton("OK", delegate
            {
                if (!string.IsNullOrEmpty(et.Text))
                    Number = et.Text;
            });
            builder.SetNegativeButton("CANCEL", delegate { builder.Dispose(); });
            builder.SetView(et);
            builder.SetCancelable(false);
            AlertDialog alertdialog = builder.Create();

            alertdialog.Show();

            alertdialog.GetButton((int)DialogButtonType.Positive).Enabled = false;

            et.AfterTextChanged += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(et.Text))
                {
                    alertdialog.GetButton((int)DialogButtonType.Positive).Enabled = true;
                }
            };

            while (string.IsNullOrEmpty(Number))
            {
                await Task.Delay(25);
            }

            //  return Number;

        }

        catch (Exception ex)
        {
            Toast.MakeText(_context, ex.Message, ToastLength.Long).Show();
            // ex.Message;
        }
    }

What to do? Please help


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>