java-android-android studio

2guxujil  于 2021-07-07  发布在  Java
关注(0)|答案(1)|浏览(417)

我想让进度对话框出现2或3秒钟。
它除了说进展之外什么都不会做。
我想添加一个延迟进度条。怎样才能成功呢?
它一开始出现,但时间很短。
我的代码如下:

private void registerNewAccount(String username,String email, String password, String mobile, String gender){
            final ProgressDialog progressDialog = new ProgressDialog( RegisterActivity.this);
            progressDialog.setCancelable(false);
            progressDialog.setIndeterminate(false);
            progressDialog.setTitle("Registering New Account");
            progressDialog.show();
            String uRl = "http://192.168.1.6/Projects/LoginRegisterAndroid/register.php";
            StringRequest request = new StringRequest(Request.Method.POST, uRl, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    if (response.equals("Successfull")){
                        progressDialog.dismiss();
                        Toast.makeText(RegisterActivity.this, response, Toast.LENGTH_SHORT).show();
                        startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
                        finish();
                    }
                    else{
                        progressDialog.dismiss();
                        Toast.makeText(RegisterActivity.this, response, Toast.LENGTH_SHORT).show();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    progressDialog.dismiss();
                    Toast.makeText(RegisterActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    HashMap<String,String> param = new HashMap<>();
                    param.put("username", username);
                    param.put("email", email);
                    param.put("psw", password);
                    param.put("mobile", mobile);
                    param.put("gender", gender);
                    return param;
                }
            };

            request.setRetryPolicy(new DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            MySingleton.getmInstance(RegisterActivity.this).addToRequestQueue(request);
        }

}
xt0899hw

xt0899hw1#

我建议使用处理程序:

new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
        @Override
        public void run() {
            // dismiss progress dialog here 
        }
}, 3000)

这可以在内部完成 onRepsonse 截击请求中的方法

相关问题