Image 如何从SD卡中删除gridview项目?

Image 如何从SD卡中删除gridview项目?,image,memory,directory,Image,Memory,Directory,我看过所有其他关于如何从SD卡中删除图像的帖子。 我知道以前有人问过这个问题,我已经实施了人们提出的所有建议,但是我一直没有得到任何结果。 所有图像都保存在我的sd卡目录中。 所以我希望有人能发现我做错了什么,因为我在这里完全迷失了方向 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act

我看过所有其他关于如何从SD卡中删除图像的帖子。 我知道以前有人问过这个问题,我已经实施了人们提出的所有建议,但是我一直没有得到任何结果。 所有图像都保存在我的sd卡目录中。 所以我希望有人能发现我做错了什么,因为我在这里完全迷失了方向

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cookbook);

    final GridView gridview = (GridView) findViewById(R.id.gridView);
    myImageAdapter = new ImageAdapter(this);
    gridview.setAdapter(myImageAdapter);
    gridview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                                       int position, long id) {
            Toast.makeText(CookbookActivity.this, "You've removed an item", Toast.LENGTH_SHORT).show();

            // Removes the image from the gridview
            myImageAdapter.remove(position);

            // Updates the gridview
            myImageAdapter.notifyDataSetChanged();
            int i = 0;
            i++;
            // Trying to delete the LongClicked Image from the SD card
            String myFile = "/Food Inspiration/" + "pic-" + i + ".png";

            String myPath = Environment.getExternalStorageDirectory()+myFile;

            File f = new File(myPath);
            Boolean deleted = f.delete();

            return true;
        }
    });
更新2.0 好的,我已经通过这个循环一次删除了每个项目:

// Deletes EVERY image when LongClicked... cant make it delete 1 image
                for (int i = 0; i < 100; i++){
                    // Trying to delete the LongClicked Image from the SD card
                    String myFile = "/Food Inspiration/" + "pic-" + i + ".png";

                    String myPath = Environment.getExternalStorageDirectory()+myFile;

                    File f = new File(myPath);
                    Boolean deleted = f.delete();

                }
//单击时删除每个图像。。。无法使其删除1个图像
对于(int i=0;i<100;i++){
//正在尝试从SD卡中删除长单击的图像
字符串myFile=“/Food Inspiration/”+“pic-“+i+”.png”;
字符串myPath=Environment.getExternalStorageDirectory()+myFile;
文件f=新文件(myPath);
布尔删除=f.delete();
}
有人知道我如何只保存一个我长按的项目,而不是一次保存所有项目吗。我知道我删除所有内容是因为I<100,但这只是出于测试目的。我希望有人能回答如何一次删除一个项目

// Deletes EVERY image when LongClicked... cant make it delete 1 image
                for (int i = 0; i < 100; i++){
                    // Trying to delete the LongClicked Image from the SD card
                    String myFile = "/Food Inspiration/" + "pic-" + i + ".png";

                    String myPath = Environment.getExternalStorageDirectory()+myFile;

                    File f = new File(myPath);
                    Boolean deleted = f.delete();

                }