protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.SeachListView); items = new List <model.EmsNum>(); ListView list = FindViewById <ListView>(Resource.Id.SearchlistView); listAdapter = new SearchAdapter(this, items); list.Adapter = listAdapter; Button searchbtn = FindViewById <Button>(Resource.Id.Searchbtn); EditText num = FindViewById <EditText>(Resource.Id.numtxt); EditText date = FindViewById <EditText>(Resource.Id.datetxt); searchbtn.Click += delegate { SqliteDataAccess dataAccess = new SqliteDataAccess(); if (string.IsNullOrWhiteSpace(num.Text) && string.IsNullOrWhiteSpace(date.Text)) { items = dataAccess.SelectAll().ToList(); } else { items = dataAccess.Select(num.Text, date.Text); } RunOnUiThread(() => { list.Adapter = new SearchAdapter(this, items); }); }; // Create your application here }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); ListView list = FindViewById <ListView>(Resource.Id.listView); list.StackFromBottom = true; list.TranscriptMode = TranscriptMode.AlwaysScroll; ActionBar.Hide(); Toolbar toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.InflateMenu(Resource.Menu.menu); toolbar.MenuItemClick += (s, e) => { switch (e.Item.ItemId) { case Resource.Id.menu_history: Intent intent = new Intent(this, typeof(SearchActivity)); StartActivity(intent); break; case Resource.Id.menu_about: dataAccess.DeleteAll(); break; } }; dataAccess = new SqliteDataAccess(); items = dataAccess.SelectAll(); nMgr = (NotificationManager)GetSystemService(NotificationService); try { SerialPortFinder serialPortFinder = new SerialPortFinder(); string[] entryValues = serialPortFinder.GetAllDevicesPath(); string[] entries = serialPortFinder.GetAllDevices(); Com.Nativec.Tools.SerialPort serialPort = new Com.Nativec.Tools.SerialPort(new File(entryValues[7]), 115200, 0); ModuleManager.NewInstance().SetUHFStatus(false); ModuleManager.NewInstance().SetScanStatus(true); mReader = new Readerbase(serialPort.InputStream, serialPort.OutputStream, items, nMgr, this); listAdapter = new ListAdapter(this, items); list.Adapter = listAdapter; thread = new Thread(update); thread.Start(); Button refreshbtn = FindViewById <Button>(Resource.Id.refresh); //int index = 0; refreshbtn.Click += delegate { //dataAccess.SaveOption(new model.EmsNum { datetime=DateTime.Now.ToLongDateString(),EMSNUM= "20752640558", state="未同步" }); //items.Add(new model.EmsNum { EMSNUM = "20752640558" + index, state = "未同步", index = index }); //items2.Add(new model.EmsNum { EMSNUM = "20752640558" + index, state = "未同步", index = index }); //SQliteHelper sql = new SQliteHelper(); //sql.insertAsync("2589" + index, "未同步"); //index++; //Button lsvButton = FindViewById<Button>(Resource.Id.lsvButton); listAdapter.NotifyDataSetChanged(); }; Button submitbtn = FindViewById <Button>(Resource.Id.submit); EditText editText = FindViewById <EditText>(Resource.Id.editText); submitbtn.Click += delegate { if (!string.IsNullOrWhiteSpace(editText.Text)) { RunOnUiThread(() => { string answer = updateToSystem(editText.Text, DateTime.Now.ToLongDateString()); if (answer != "err") { items.Add(new model.EmsNum() { EMSNUM = editText.Text, state = answer, index = items.Count + 1 }); listAdapter.NotifyDataSetChanged(); editText.Text = ""; Toast.MakeText(this.ApplicationContext, "提交成功", ToastLength.Long).Show(); } else { Toast.MakeText(this.ApplicationContext, "网络异常,请稍后重试", ToastLength.Long).Show(); } }); } else { Toast.MakeText(this.ApplicationContext, "请输入单号", ToastLength.Long).Show(); } }; } catch (Java.Lang.Exception ex) { Toast.MakeText(this.ApplicationContext, ex.ToString(), ToastLength.Long).Show(); } }