I want to show ProgressDialog when http connection request.
there is request method.
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;
}
but when this method running. the ProgressDialog not showing. how to solve this problem?
You need to call 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().
Also, what I do suggest is that you do this in AsyncTask class' doInBackground().
In the onPreExecute(), display the ProgressDialog and in the onPostExecute() dismiss it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With