android - 从 sqlite 中删除不起作用

标签 android sqlite android-sqlite

你好,我正在制作一个预算应用程序,它可以让你查看输入的费用,如果需要删除它们,我可以调用方法运行它,它不会有问题,但是当我检查它是否有效时我还没有尝试过,但无法弄清楚为什么这不起作用。我使用警告对话框来确认他们要删除。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    this);

                // set title
                alertDialogBuilder.setTitle("DELETE "+position);

                // set dialog message
                alertDialogBuilder
                    .setMessage("Are you sure you whant to delete Expeance "+position)
                    .setCancelable(false)

                    .setPositiveButton("yes", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub
                            String[]    po = position.split(" ");
                            String  date = po[0];
                            date = date +".tar.gz";
                            entry.open();
                            entry.deleteByDate(date);
                            entry.close();
                        recreate();
                        }

                    })
                    .setNegativeButton("No",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, just close
                            // the dialog box and do nothing
                            dialog.cancel();
                        }
                    });

                    // create alert dialog
                    AlertDialog alertDialog = alertDialogBuilder.create();

                    // show it
                    alertDialog.show();

这是方法的代码

public SQLiteDatabase deleteByDate(String date2) 
        {
            // TODO Auto-generated method stub

            ourDatabase.delete(DATABASE_TABLE2, KEY_DATE + " =?", new String[] { date2 });
            ourDatabase.delete(DATABASE_TABLE4, KEY_DATE + " =?", new String[] { date2 });
            return ourDatabase;

        }

最佳答案

使用 Pattern.compile"/" 替换为 "-" 而不是 date.replace("/", "_"):

    Pattern p = Pattern.compile("/");
    String  date = po[0];
    Matcher matcher = p.matcher(date);
    date = matcher.replaceAll("_");

    date = date +".tar.gz";
    //your code here....

关于android - 从 sqlite 中删除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13881728/

相关文章:

android - 如何在sqlite for android中实现一对多的对象数据库

android - 从外部存储 SD 卡打开数据库

Android 房间 - 如何清除所有表的 sqlite_sequence

java - 在后台更新位置并检查 LocationSettings

java - 将 MatOfPoint2f 转换为 MatOfPoint

android - 是否有可能知道我的位置来自 gps 或 glonass?

mysql - 使用迁移文件将 MySQL-DB-Dump 导入 Rails 应用程序

android - 我的应用程序在api 23上运行并在api 11上崩溃

java - 批量插入不插入

java - 处理 Volley 中的错误(有 future )?