如何从自定义文件夹中删除图像 [英] How to delete an image from a custom folder

查看:68
本文介绍了如何从自定义文件夹中删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我删除的图像会从应用程序的列表视图中删除,但不会从应用程序的自定义文件夹中删除。daodb是我的数据库的名称。

代码:

In the code below,the image which i delete gets deleted from the app's listview but not from the custom folder of the app."daodb" is the name of my database.
Code:

Toast.makeText(getApplicationContext(), image + " " + " is deleted.", Toast.LENGTH_LONG).show();
Log.d("Delete Image: ", "Deleting.....");
daOdb.deleteImage(image);
daOdb.getImages();
File fdelete = new File(image.getPath());
if (fdelete.exists())

{
    if (fdelete.delete()) {
        System.out.println("File Deleted :" + image.getPath());
    } else {
        System.out.println("File Not Deleted :" + image.getPath());
    }
}

adapter.remove(adapter.getItem((int) position));
public void deleteImage(MyImage image) {
    String whereClause = DBhelper.COLUMN_TITLE + "=? AND " + DBhelper.COLUMN_DATETIME +                    "=?";
    String[] whereArgs = new String[]{image.getTitle(), String.valueOf(image.getDatetimeLong())};
    database.delete(DBhelper.TABLE_NAME, whereClause, whereArgs);

}

推荐答案

你的代码回头看我。首先显示一条Toast消息,告诉用户该图像已被删除。接下来,从数据库中删除它。接下来,您尝试获取刚刚从数据库中删除的项目的路径。等等。


使用调试器逐步执行代码,看看每个步骤的变量值是什么。我怀疑对 fdelete.exists()的调用失败,因为路径无效。
Your code looks back to front to me. You start by showing a toast message telling the user that the image is deleted. Next you delete it from the database. Next you try to get the path of the item that you have just deleted from the database. etc.

Use your debugger to step through the code and see what the values of your variables are at each step. I suspect the call to fdelete.exists() is failing because the path is invalid.


这篇关于如何从自定义文件夹中删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆