1

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

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;

        }
4

1 回答 1

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....
于 2012-12-14T15:49:55.930 回答