ProgressDialog关闭onClick

时间:2012-11-20 19:10:37

标签: android dialog onclick android-asynctask

我启动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();
    }       

3 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:1)

答案 2 :(得分:0)

尝试:

dialog.setIndeterminate();
dialog.setCancelable(false);