![](/img/trans.png)
[英]I'm trying to fetch the content of website and making it to display in the android app
[英]I'm making a renaming application in Android
我想在執行重命名任務時顯示進度對話框。 單擊重命名按鈕后,將出現該對話框。 但是,重命名功能(循環)結束后,將顯示進度對話框。 這是我的代碼
public void onRenameClicked(View v){
ProgressTask task = new ProgressTask();
task.execute();
for(int i = 0; i < num_of_files; i++){
rename(file[i]);
}
}
這是內部類以顯示對話框
class ProgressTask extends AsyncTask<Integer, Void, Void>{
ProgressDialog pd = new ProgressDialog(MainActivity.this);
@Override
protected Void doInBackground(Integer... i) {
for(int j = 0; j < item.size(); j++) {
pd.setProgress(j);
pd.setMessage((j) + "/" + item.size());
}
return null;
}
@Override
protected void onPreExecute() {
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setTitle("변경중");
pd.setMax(item.size());
pd.show();
}
}
你必須用
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
pd.setProgress(values[0]);
pd.setMessage((values[0]) + "/" + values[1]);
}
和
publishProgress(j, item.size());
在doInBackground()
。 這些修改是必需的,因為setProgress
和setMessage
必須在UI線程中而不是在后台線程中執行。
您確實意識到您正在調用異步任務,而沒有數據..因此它很快完成。 你或許應該在傳遞通過參數文件到的AsyncTask的列表,然后相應地處理這些電話為每個文件里面的AsyncTask和更新的AsyncTask的進度完成重命名文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.