我有一个 ListView ,显示文件夹内的所有文件。 使用OnItemLongClickListener删除文件的方法是什么?
谢谢。
最佳答案
在OnItemLongClickListener()
方法中调用此方法。这里的path.get(position)是我使用的ArrayList。您应该根据您的要求提供文件位置来更改它。
public void doDeleteFile(ListView l, View v, int position, long id){
File fileToDelete = new File(path.get(position));
if(!fileToDelete.isDirectory()){
try{
if(fileToDelete.delete()){
System.out.println("File deleted successfull !");
}else{
System.out.println("File delete operation failed");
}
}catch(Exception ex){
System.out.println("Exception :"+ex.getMessage());
}
}else{
System.out.println("It is not a file");
}
关于java - 如何使用 OnItemLongClickListener 删除存储在我的设备中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22290991/