删除从sqlite无效

时间:2012-12-14 15:36:33

标签: 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;

        }

1 个答案:

答案 0 :(得分:2)

使用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....