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