Esempio n. 1
0
        private void loadData()
        {
            _listSource = _db.selectTablePerson();
            var adapter = new ListViewAdapter(this, _listSource);

            _listData.Adapter = adapter;
        }
Esempio n. 2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.AddFragment, container);

            //initialize buttons
            _cancelBtn = view.FindViewById <Button>(Resource.Id.cancelBtn);
            _submitBtn = view.FindViewById <Button>(Resource.Id.submitBtn);

            //initialize texts
            _firstNameTxt   = view.FindViewById <EditText>(Resource.Id.firstNametxt);
            _lastNameTxt    = view.FindViewById <EditText>(Resource.Id.LastNametxt);
            _phoneNumberTxt = view.FindViewById <EditText>(Resource.Id.phoneNumtxt);


            _cancelBtn.Click += (sender, e) =>
            {
                Dismiss();
            };
            _submitBtn.Click += (sender, e) =>
            {
                Regex letterRegex = new Regex("^[a-zA-z]+$$");
                Regex numRegex    = new Regex("^(0|[1-9][0-9]*)$");
                if (letterRegex.IsMatch(_firstNameTxt.Text) && letterRegex.IsMatch(_lastNameTxt.Text) && numRegex.IsMatch(_phoneNumberTxt.Text))
                {
                    Person person = new Person()
                    {
                        FirstName = _firstNameTxt.Text, LastName = _lastNameTxt.Text, PhoneNumber = _phoneNumberTxt.Text
                    };
                    _dataBase.insertIntoTablePerson(person);

                    _listPeople = _dataBase.selectTablePerson();
                    var adapter = new ListViewAdapter(_mainActivity, _listPeople);
                    _listView.Adapter = adapter;

                    Dismiss();
                }
                else
                {
                    AlertDialog.Builder dialog = new AlertDialog.Builder(view.Context, AlertDialog.ThemeHoloLight);
                    AlertDialog         alert  = dialog.Create();
                    alert.SetTitle("Title");
                    alert.SetMessage("Please enter a valid name and phone number");
                    alert.SetButton("OK", (c, ev) =>
                    {
                        alert.Dismiss();
                    });
                    alert.Show();
                }
            };

            return(view);
        }