简体   繁体   中英

Can't dismiss a progress dialog

I have a ProgressDialog that is displayed while I fetch data from parse. And it should dismiss when its done, but it doesn't.

private ProgressDialog progress;
mainAdapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<ParseObject>(){
        @Override
        public void onLoading() {
            progress = ProgressDialog.show(this, "Tittle","Message", true);
        }
        @Override
        public void onLoaded(List<ParseObject> parseObjects, Exception e) {
            progress.dismiss();
        }
    });

I've tried working with threads, I've used progress.cancel() and progress.hide() but for some reason the ProgressDialog does not close and stays on screen even after the dismiss comand.

progress = ProgressDialog.show(this, "Tittle","Message", true);

actually is

    public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate) {
    return show(context, title, message, indeterminate, false, null);
}

and it call this method

    public static ProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate,
        boolean cancelable, OnCancelListener cancelListener) {
    ProgressDialog dialog = new ProgressDialog(context);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(cancelListener);
    dialog.show();
    return dialog;
}

so the cancelable is false . Try to use

progress = ProgressDialog.show(this, "Tittle","Message", true, true);

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM