2016-04-01 87 views
1

我想刪除與進度條 文件夾和內容的內容,請大家幫我刪除文件夾,並用進度條

void deletRecursive(File fileOrDirectory){ 
    if(fileOrDirectory.isDirectory()){ 
     for(File child :fileOrDirectory.listFiles()) 
      deletRecursive(child); 
     fileOrDirectory.delete(); 
    } 
    if(!fileOrDirectory.delete()){ 


    } 
} 

回答

1

使用一個的AsyncTask。例如。

private class BackgroundTask extends AsyncTask <Void, Void, Void> { 
    private ProgressDialog dialog; 

    public BackgroundTask(MyMainActivity activity) { 
     dialog = new ProgressDialog(activity); 
    } 

    @Override 
    protected void onPreExecute() { 
     dialog.setMessage("Doing something, please wait."); 
     dialog.show(); 
    } 

    @Override 
    protected void onPostExecute(Void result) { 
     if (dialog.isShowing()) { 
      dialog.dismiss(); 
     } 
    } 

    @Override 
    protected Void doInBackground(Void... params) { 
     //do your work 

     return null; 
    } 

} 

如果你想報告進度,可以使你的對話不是不確定的,在執行onProgressUpdate。那麼你可以在doInBackground中使用publishProgress