//------------------------------------------------------------------------// //UI operation: we need to find a neat way, as to do this operation async and tie this with UI thread later on async void dbupdateUI(scrolloptions sclopt) { if( null == mItemList) mItemList = new ObservableCollection<ShopItem>(); //create the db helper class var dbhelper = new DBHelper(DBGlobal.DatabasebFilePath, this); //create or open shopitem database var result = dbhelper.create_database(); if (!result) { Toast.MakeText(this, "Failed to open / create the database ", ToastLength.Long).Show(); return; } var db_list = dbhelper.query_selected_values("select * from ShopItem"); //if there were no entries then we might hv got a null, in that case, take them to add a new entry if (db_list != null) { mItemList.Clear(); foreach (var shopping_item in db_list) { mItemList.Add(shopping_item); } } if( mfiltered_list.Count > 0 ) { mfiltered_list.Clear(); foreach(var newitem in mItemList) { mfiltered_list.Add(newitem); } } m_adapter.NotifyDataSetChanged(); switch (sclopt) { case scrolloptions.scroll_to_bottom: await Task.Delay(1000); mListview.SmoothScrollToPosition(m_adapter.Count - 1); break; case scrolloptions.scroll_to_top: await Task.Delay(1000); mListview.SmoothScrollToPosition(0); break; default: case scrolloptions.scroll_none: break; } }
private List<ShopItem> get_all_shopitems() { List<ShopItem> shop_items = new List<ShopItem>(); //create the db helper class var dbhelper = new DBHelper(DBGlobal.DatabasebFilePath,this); //create or open shopitem database var result = dbhelper.create_database(); var db_list = dbhelper.query_selected_values("select * from ShopItem"); //if there were no entries then we might hv got a null, in that case, take them to add a new entry if (db_list != null) { shop_items.Clear(); foreach (var shopping_item in db_list) { shop_items.Add(shopping_item); } } return shop_items; }