public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. var connection = new SQLiteConnection(new SQLitePlatformIOS(), "savedItems.sqlite"); _repository = new SavedItemRepository(connection); _savedItems = _repository.GetAll(); UpdateTotalLabel(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); EditText descriptionText = FindViewById<EditText>(Resource.Id.descriptionText); EditText priceText = FindViewById<EditText>(Resource.Id.priceText); TextView totalText = FindViewById<TextView>(Resource.Id.totalSavedText); Button saveButton = FindViewById<Button>(Resource.Id.saveButton); var path = System.IO.Path.Combine(System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal), "savedItems.sqlite"); var connection = new SQLiteConnection(new SQLitePlatformAndroid(), path); _repository = new SavedItemRepository(connection); _savedItems = _repository.GetAll(); UpdateTotalLabel(totalText); saveButton.Click += (sender, e) => { decimal price = 0; if (decimal.TryParse(priceText.Text, out price)) { var savedItem = new SavedItem(); savedItem.Date = DateTime.Now; savedItem.Description = descriptionText.Text; savedItem.Price = price; _savedItems.Add(savedItem); _repository.Create(savedItem); UpdateTotalLabel(totalText); descriptionText.Text = string.Empty; priceText.Text = string.Empty; HideKeyBoard(); } }; Button detailsButton = FindViewById<Button>(Resource.Id.detailsButton); detailsButton.Click += DetailsButton_Click; }