progressDIalog.setCancelable(false)不起作用,触摸时关闭

时间:2019-06-01 10:38:02

标签: android

我有一个进度对话框,当我在线获取一些jSON数据时会出现。我希望它保留在屏幕上,直到提取完成。但是,当用户触摸某个地方时,它就会消失。我该如何预防?

我已经尝试过:How to avoid dismissing my progress dialog when the user touches the screen?和其他一些人。

但是,它们都无法解决我的问题。我已经尝试用getRetainInstance代替false,仍然无法正常工作。

这是我的代码:

public class Login extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    parentHolder = inflater.inflate(R.layout.fragment_login, container, false);
    downloadJSON(url);
    return parentHolder;
}

private void downloadJSON(final String urlWebService) {
    class DownloadJSON extends AsyncTask<Void, Void, String> {

        private ProgressDialog dialog = new ProgressDialog(getActivity());

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            this.dialog.setMessage("Please wait");
            this.dialog.setCancelable(false);
            this.dialog.setCanceledOnTouchOutside(false);
            this.dialog.show();
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            if (dialog.isShowing()) {
                dialog.dismiss();
            }

            try {
                loadIntoListView(s);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        protected String doInBackground(Void... voids) {
            // some code
        }
    }
}

private void loadIntoListView(String json) throws JSONException {
    // Some code
}
}

0 个答案:

没有答案