• 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;
            }

    效果图如下

  • 相关阅读:
    leetcode203
    leetcode88
    leetcode219
    leetcode225
    2018-12-25-C#-使用转换语义版本号
    2018-12-25-C#-使用转换语义版本号
    2018-10-15-Winforms-可能遇到的-1000-个问题
    2018-10-15-Winforms-可能遇到的-1000-个问题
    2018-8-10-UWP-WPF-解决-xaml-设计显示异常
    2018-8-10-UWP-WPF-解决-xaml-设计显示异常
  • 原文地址:https://www.cnblogs.com/lihuazou/p/4336984.html
Copyright © 2020-2023  润新知