进度对话没有被驳回

时间:2016-10-27 02:38:31

标签: android android-volley progressdialog

我正在研究可以做CRUD的目录项目。在每个CRUD进程中它显示ProgressDialog。

问题是“更新数据目录”没有被解雇并且永远运行直到MJ忘记如何说唱。我不明白为什么。请帮忙

代码

public void updateProduct(final String id, final String name, final String price, final String category, final String description, @Nullable String imageBase64) {
    Log.i("zihad", "updateProduct()");
    progressDialog = ProgressDialog.show(context, "Update data catalog", "Please wait ...");
    StringRequest myStringRequest = new StringRequest(Request.Method.POST, MainActivity.URL_SERVER+"/updateproduct.php",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String jsonResponse) {
                    progressDialog.dismiss();
                    Log.i("zihad", "updateProduct().onResponse()");
                    try {
                        JSONObject jObject = new JSONObject(jsonResponse);
                        if (jObject.getBoolean("success")) {
                            Toast.makeText(context, "Product has been updated", Toast.LENGTH_SHORT).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            myDefaultErrorListener) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> mapParam = new HashMap<>();
            mapParam.put("id", id);
            mapParam.put("name", name);
            mapParam.put("price", price);
            mapParam.put("category", category);
            mapParam.put("description", description);

            return mapParam;
        }
    };
    requestQueue.add(myStringRequest);

    if (imageBase64 != null) {uploadImageProduct(id, imageBase64);}
}

public void uploadImageProduct(final String id, final String imageBase64) {
    Log.i("zihad", "uploadImageProduct()");
    progressDialog = ProgressDialog.show(context, "Upload image catalog", "Please wait ...");
    StringRequest myStringRequest = new StringRequest(Request.Method.POST, MainActivity.URL_SERVER+"/uploadimage.php",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String jsonResponse) {
                    Log.i("zihad", "uploadImageProduct().onResponse()");
                    progressDialog.dismiss();
                }
            },
            myDefaultErrorListener) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> mapParam = new HashMap<>();
            mapParam.put("id", id);
            mapParam.put("imageBase64", imageBase64);

            return mapParam;
        }
    };
    requestQueue.add(myStringRequest);
}

记录屏幕截图 enter image description here

3 个答案:

答案 0 :(得分:0)

尝试将进度对话框设置为确定。在

之后的代码中
progressDialog = ProgressDialog.show(context, "Update data catalog", "Please wait ...");

添加以下行:

progressDialog.setIndeterminate(false);

答案 1 :(得分:0)

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(); // show the dialog
    return dialog;
}

回调方法 onResponse 在您的服务器响应之前不会被调用。

show()方法将为您创建并显示一个对话框,因此如果您在不关闭第一个方法的情况下调用该方法两次,则第一个方法将永远不会被忽略,因为该对话框的引用不会被使用。

答案 2 :(得分:0)

 final viewProgressDialogue viewProgressDialogue = new viewProgressDialogue(DebugActivity.this);
    viewProgressDialogue.show();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Log.d("response","im calling");
            viewProgressDialogue.dismiss();
        }
    }, 5000);