private void MListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { //Needs implementation to write item to list and return to Shoppinglist listview string auswahl = mItems[e.Position]; //Needs to load Product Classes.Product newProduct = Classes.Database.returnProduct(auswahl); //Load List (name = getStringExtra) Classes.Shoppinglist sl = Classes.ListStorer.LoadList(listName); //Needs to add Product to list sl.addProduct(newProduct); //Store list Classes.ListStorer.StoreList(sl); //Parse back name Intent intent = new Intent(this, typeof(ListEditorActivity)); intent.PutExtra("listname", listName); //Give controll to listeditoractivity this.StartActivity(intent); }
public static Shoppinglist LoadList(string listName) { var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); var filename = Path.Combine(path, "lists.csv"); if (File.Exists(filename) == false) { FileStream fs = new FileStream(filename, FileMode.Create); fs.Close(); } Shoppinglist list = new Shoppinglist(); using (StreamReader sr = new StreamReader(filename)) { string line = sr.ReadLine(); while (line != null) { if (line == listName) //Liste mit dem eingegebenen Namen suchen { list = new Shoppinglist(); list.Name = line; line = sr.ReadLine(); while (line != null && line.Contains(";")) { string[] zeile = line.Split(';'); Product prod = new Product(zeile[0], zeile[1], Convert.ToInt32(zeile[2]), Convert.ToInt32(zeile[3])); list.addProduct(prod); line = sr.ReadLine(); } // Wenn die Zeile keinen ; mehr enthält beginnt eine neue Liste return(list); } line = sr.ReadLine(); } return(null); // Wenn die Liste nicht gefunden wurde } }