我有一個AsyncTask
,我在onPreExecute()
方法中設置消息ProgressDialog
。現在我想更新ProgressDialog
的消息,方法是從StartUpload()
方法doInbackground
調用。Upadate progressdialog消息
class performBackgroundtask extends AsyncTask<Void, Void, Void> {
// @Override
public void onPreExecute()
{
connectionProgressDialog = new ProgressDialog(ProcessReportsUploadActivity.this);
connectionProgressDialog.setCancelable(false);
connectionProgressDialog.setCanceledOnTouchOutside(false);
connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
connectionProgressDialog.setMessage("Uploading data...");
connectionProgressDialog.show();
}
// @Override
public Void doInBackground(Void... params)
{
try
{
StartUpload();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
// @Override
public void onPostExecute(Void result)
{
connectionProgressDialog.dismiss();
connectionProgressDialog.cancel();
}
}
我試圖更新陸侃酒吧,但publishProgress()被調用一次。我想在StartUpload()方法中聲明的方法中定期更新消息。 – ykumbhar
use publishProgress(「」+(int)((total * 100)/ lenghtOfFile));在你的while循環中 –
如何調用publishProgress(「」+(int)((total * 100)/ lenghtOfFile));在StartUpload()方法中? – ykumbhar