Beispiel #1
0
        void OpenAddDialog()
        {
            var         alert      = UIAlertController.Create("Create new contact", "Enter name and phone", UIAlertControllerStyle.Alert);
            UITextField fieldName  = null;
            UITextField fieldPhone = null;

            alert.AddTextField((Name) =>
            {
                fieldName                    = Name;
                fieldName.Placeholder        = "Name";
                fieldName.AutocorrectionType = UITextAutocorrectionType.No;
                fieldName.KeyboardType       = UIKeyboardType.Default;
                fieldName.ReturnKeyType      = UIReturnKeyType.Done;
                fieldName.ClearButtonMode    = UITextFieldViewMode.WhileEditing;
            });
            alert.AddTextField((Phone) =>
            {
                fieldPhone                    = Phone;
                fieldPhone.Placeholder        = "Phone";
                fieldPhone.AutocorrectionType = UITextAutocorrectionType.No;
                fieldPhone.KeyboardType       = UIKeyboardType.PhonePad;
                fieldPhone.ReturnKeyType      = UIReturnKeyType.Done;
                fieldPhone.ClearButtonMode    = UITextFieldViewMode.WhileEditing;
            });

            alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, alertAction => { }));

            alert.AddAction(UIAlertAction.Create("Save", UIAlertActionStyle.Default, (UIAlertAction obj) =>
            {
                addUserContacts.AddContact(position: 0, fieldName.Text, fieldPhone.Text, "avatar_default");
                contactsTableView.ReloadData();
            }));
            PresentViewController(alert, true, null);
        }
Beispiel #2
0
        void openAddDialog()
        {
            var layoutInflater = LayoutInflater.From(Application.Context);
            var view           = layoutInflater.Inflate(Resource.Layout.dialog_addcontact, null);

            var name  = view.FindViewById <EditText>(Resource.Id.contactname);
            var phone = view.FindViewById <EditText>(Resource.Id.contactphone);

            var builder = new AlertDialog.Builder(this);

            builder.SetView(view);
            var alertDialog = builder.Create();

            alertDialog.SetTitle("New contact");
            alertDialog.SetButton("New", (s, e) =>
            {
                var position = 0;
                addUserContacts.AddContact(position, name.Text, phone.Text, "avatar_default");
                adapter.NotifyItemInserted(position);
                recycler.SmoothScrollToPosition(position);
            });

            alertDialog.SetButton2("Cancel", (s, e) =>
            {
                alertDialog.Cancel();
            });
            alertDialog.Show();
        }