我想做的第一件事是在我的应用程序列表活动中添加一个进度对话框。该活动并不耗时(无论如何也不多),但是当活动从 json 解析中解析数据并嵌入到 listactivity 中时,您不希望 UI 无响应,给用户留下不好的印象。请帮帮我
问问题
86 次
1 回答
0
在解析数据时使用 AsyncTask 显示进度对话框
private class DownloadingProgressTask extends
AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog = new ProgressDialog(ShowDescription.this);
/** progress dialog to show user that the backup is processing. */
/** application context. */
protected void onPreExecute() {
this.dialog.setMessage("Please wait");
this.dialog.show();
}
protected Boolean doInBackground(final String... args) {
try {
downloadFile(b.getString("URL"));
return true;
} catch (Exception e) {
Log.e("tag", "error", e);
return false;
}
}
@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
if (success) {
Toast.makeText(ShowDescription.this,
"File successfully downloaded", Toast.LENGTH_LONG)
.show();
//imgDownload.setVisibility(8);
} else {
Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG)
.show();
}
}
}
于 2012-06-27T05:27:11.220 回答