我正在尝试在java'A'中显示进度对话框。在那个从'A'调用java'B'的类的时刻,它从Web服务下载数据并将数据保存到文件中。它没有显示的进度对话框。我正在使用的代码是:
ProgressDlg= ProgressDialog.show(Doctor.this, "","Loading. Please wait...", true);
String time_batch=mDataIntent.getExtras().getString("TIME_BATCH");
String patientid=mDataIntent.getExtras().getString("PatientId")
mGetHeartRate = new GetHeartRate(Doctor.this, mHandler);
mgetEcgAnalized = new getEcgAnalized(Doctor.this, mHandler);
mGetHeartRate.getHeart(patientid,time_batch);
mgetEcgAnalized.getECG(patientid, time_batch, "I".toString());
ProgressDlg.dismiss();
答案 0 :(得分:1)
您是否在AsyncTask中执行ProgressDialog?像这样:
public class ExampleTask extends AsyncTask<String, Integer, String> {
private ProgressDialog progressDlg;
private Context context;
private Handler progressHandler;
public ExampleTask(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
progressHandler = new Handler();
}
@Override
protected String doInBackground(String... params) {
//to do
}
@Override
protected void onPostExecute(String filePath) {
if (progressDlg != null) {
progressDlg.dismiss();
progressDlg = null;
}
}
@Override
protected void onProgressUpdate(final Integer... values) {
final int progress = values[0] / 1000;
if (progressDlg == null) {
progressHandler.post(new Runnable() {
@Override
public void run() {
final int max = values[1] / 1000;
progressDlg = new ProgressDialog(context);
progressDlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDlg.setMessage("Message");
progressDlg.setMax(max);
progressDlg.show();
}
});
} else {
progressDlg.setProgress(progress);
}
}
}
答案 1 :(得分:0)
这适合我。
ProgressDialog dialog = ProgressDialog.show(activity, "", PopUpHelper.LOADING, true);
dialog.show();