Xamarin Android 记事本(三)删改
这篇我就不做太多的说明了,数据操作之前也都举过例子了,这里就直接贴出删除和修改的代码。
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case 1: { Android.App.AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog ad = builder.Create(); ad.SetTitle("是否删除"); ad.SetButton("是", (s, e) => { Sqlite dbHelper = new Sqlite(this); SQLiteDatabase db = dbHelper.WritableDatabase; ContentValues ncv = new ContentValues(); var NID = Intent.GetStringExtra("id"); ncv.Put("context", edtext.Text); db.Delete("NoteBooksql", " _id = ? ", new string[] { NID.ToString() }); var intentAct2 = new Intent(this, typeof(Activity1)); StartActivity(intentAct2); Toast.MakeText(this, "已删除", ToastLength.Short).Show(); this.Finish(); }); ad.SetButton2("否", (s, e) => { }); ad.Show(); } break; case 2: { Sqlite dbHelper = new Sqlite(this); SQLiteDatabase db = dbHelper.WritableDatabase; ContentValues ncv = new ContentValues(); var NID = Intent.GetStringExtra("id"); ncv.Put("context", edtext.Text); db.Update("NoteBooksql", ncv, " _id = ? ", new string[] { NID.ToString() }); var intentAct2 = new Intent(this, typeof(Activity1)); StartActivity(intentAct2); Toast.MakeText(this, "已保存", ToastLength.Short).Show(); this.Finish(); }break; case Android.Resource.Id.Home: { var intent = new Intent(this, typeof(Activity1)); StartActivity(intent); this.Finish(); } break; } return true; }
效果图如下
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。