4

我开始AsyncTask加载一个需要一些时间的文件。为了通知用户我正在显示一个ProgressDialog,但是如果我触摸屏幕,它会ProgressDialog立即关闭。这可能是什么原因?

 public LoadTask(Activity activity, FaceRecognizer recognizer,SecretKey key) {
    this.key = key;     
    this.recognizer = recognizer;       
    dialog = new ProgressDialog(activity);

}

@Override
protected void onPreExecute() {
    dialog.setMessage("Loading the recognizer...");
    dialog.show();
}

@Override
protected Boolean doInBackground(Void... params) {
    recognizer.load(key);
    return null;
}

@Override
protected void onPostExecute(Boolean result) {

    if (dialog.isShowing()) {
        dialog.dismiss();
    }       
4

3 回答 3

6

用这个...

public LoadTask(Activity activity, FaceRecognizer recognizer,SecretKey key) {
    this.key = key;     
    this.recognizer = recognizer;       
    dialog = new ProgressDialog(activity);
     /////////////////////////////////////////// 
    dialog.setCancelable(false);
           //or////////
    dialog.setCanceledOnTouchOutside(false);
}
于 2012-11-20T19:46:59.697 回答
1

尝试:dialog.setCanceledOnTouchOutside(false)

于 2012-11-20T19:22:50.957 回答
0

尝试:

dialog.setIndeterminate();
dialog.setCancelable(false);
于 2012-11-20T19:47:26.733 回答