I have a ProgressDialog running in a AsyncTask.
I`m trying to achive that as soon as the Length of a buffer is bigger then lets say 10000, the message from the ProgressDialog changes.
Can somebody help me please, is this possible?
Thank you in advance.
@Override
protected void onProgressUpdate(Integer... progUpdate) {
if (progUpdate[0] >= 10000){
progress.setMessage("Informatie wordt opgehaald....");
}
}
The buffer is created in a AsyncTask doInBackGround:
try {
HttpResponse response = httpClient.execute(request);
System.out.println("Response: " + response.getEntity().getContentLength());
/******* READ CONTENT IN BUFFER *******/
InputStream inputStreamActivity = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStreamActivity));
StringBuilder sb = new StringBuilder();
String line = null;
int count = sb.length();
while ((line = reader.readLine()) != null) {
sb.append(line);
publishProgress(sb.length());
}
/******* CLOSE CONNECTION AND STREAM *******/
System.out.println(sb);
inputStreamActivity.close();
kpn = sb.toString();
httpClient.getConnectionManager().shutdown();
}
To change your dialog’s message, you’ll want to use the onProgressUpdate method of the AsyncTask and define the 2nd paramater of your AsyncTask as an Integer. The onProgressUpdate will look something like:
To call this, you’ll want to update these lines in your doInBackground method of your AsyncTask:
And get rid of that Runnable. You don’t need it. Take a look at the official android documentation for AsyncTask here: http://developer.android.com/reference/android/os/AsyncTask.html There’s a great example for you on that page.