我想在 http 连接请求时显示 ProgressDialog。
有请求方法。
protected Result request(String urlStr, String postData) {
ProgressDialog dialog = ProgressDialog.show(activity, "", "Loading...",true);
Result result = new Result();
String message = "";
try {
message = HttpRequest.postURL(urlStr, postData);
result = new Result(message);
} catch (Exception e) {
Log.e(TAG,"Failed to request data from " + urlStr + "\n" + e.getMessage());
}
dialog.dismiss();
return result;
}
但是当这个方法运行时。 ProgressDialog 未显示。 如何解决这个问题?
最佳答案
你需要调用dialog.show()
Start the dialog and display it on screen. The window is placed in the application layer and opaque. Note that you should not override this method to do initialization when the dialog is shown, instead implement that in
onStart()
.
此外,我建议您在 AsyncTask
类的 doInBackground()
中执行此操作。
在 onPreExecute()
中,显示 ProgressDialog
并在 onPostExecute()
中关闭它。
关于android - 发出 HTTP 请求时未显示 ProgressDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18178340/