我想等待请求响应,用Progressbar Android-JAVA阻塞用户屏幕

我想等待请求响应,用Progressbar Android-JAVA阻塞用户屏幕,java,android,android-studio,Java,Android,Android Studio,我是第一个使用Android(Java)的人,我希望在请求结束时用Progressbar阻止用户屏幕,从而获得请求响应 Intent intent= new Intent(iniciarSesion.this, MainActivity.class); intent.putExtra("id",id); intent.putExtra("nom_usu",nom_usu); intent.putExtra("equipo",

我是第一个使用Android(Java)的人,我希望在请求结束时用Progressbar阻止用户屏幕,从而获得请求响应

Intent intent= new Intent(iniciarSesion.this, MainActivity.class);
            intent.putExtra("id",id);
            intent.putExtra("nom_usu",nom_usu);
            intent.putExtra("equipo",equipo);
            intent.putExtra("password",password);
            startActivity(intent);





   if (equipo.equals("S")) {
  añadirequipo x =  new añadirequipo();
  x.nombreCancha(id,getApplicationContext());  }



public void nombreCancha(String idUsuario,Context mContext) {


String URL="url"+idUsuario+"";
    JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            JSONObject jsonObject = null;


                for (int i = 0; i < response.length(); i++) {
                    try {
                        jsonObject = response.getJSONObject(i);

                        id_equipo = jsonObject.getString("idequipo");
                        id_usu = jsonObject.getString("idusuario");
                        nombre_equipo = jsonObject.getString("nombre_equipo");
                        cancha = jsonObject.getString("cancha");

                    } catch (JSONException e) {
                        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
                        Log.v("Fallo_Json:", e.getMessage());
                    }
                }


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error.toString().equals("com.android.volley.ParseError: org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONArray")){

                Toast.makeText(mContext, "No existe ese usuario", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "Fallo json"+error.getMessage(), Toast.LENGTH_SHORT).show();
                Log.v ("Fallo_Listener:", error.getMessage());
            }


        }
    }
    );

    requestQueue= Volley.newRequestQueue(mContext);
    requestQueue.add(jsonArrayRequest);
}

发生的情况是,在响应片段完成之前,我希望应用程序在响应结束时停止,并在响应结束时放置一个Progressbar

Intent intent= new Intent(iniciarSesion.this, MainActivity.class);
            intent.putExtra("id",id);
            intent.putExtra("nom_usu",nom_usu);
            intent.putExtra("equipo",equipo);
            intent.putExtra("password",password);
            startActivity(intent);





   if (equipo.equals("S")) {
  añadirequipo x =  new añadirequipo();
  x.nombreCancha(id,getApplicationContext());  }



public void nombreCancha(String idUsuario,Context mContext) {


String URL="url"+idUsuario+"";
    JsonArrayRequest jsonArrayRequest=new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            JSONObject jsonObject = null;


                for (int i = 0; i < response.length(); i++) {
                    try {
                        jsonObject = response.getJSONObject(i);

                        id_equipo = jsonObject.getString("idequipo");
                        id_usu = jsonObject.getString("idusuario");
                        nombre_equipo = jsonObject.getString("nombre_equipo");
                        cancha = jsonObject.getString("cancha");

                    } catch (JSONException e) {
                        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
                        Log.v("Fallo_Json:", e.getMessage());
                    }
                }


        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error.toString().equals("com.android.volley.ParseError: org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONArray")){

                Toast.makeText(mContext, "No existe ese usuario", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "Fallo json"+error.getMessage(), Toast.LENGTH_SHORT).show();
                Log.v ("Fallo_Listener:", error.getMessage());
            }


        }
    }
    );

    requestQueue= Volley.newRequestQueue(mContext);
    requestQueue.add(jsonArrayRequest);
我知道请求是一个异步线程,我不想做它的同步,我希望应用程序等待它结束加载栏

注1:

你好

Toast.makeText(getApplicationContext(), "Bienvenido "+nom_usu+" ", Toast.LENGTH_SHORT).show();
                Intent intent= new Intent(iniciarSesion.this, MainActivity.class);
                intent.putExtra("id",id);
                intent.putExtra("nom_usu",nom_usu);
                intent.putExtra("equipo",equipo);
                intent.putExtra("password",password);
                startActivity(intent);
                if (equipo.equals("S")) {
                    loader.setVisibility(VISIBLE);
                    getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
                            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                    añadirequipo x =  new añadirequipo();
                    x.nombreCancha(id,getApplicationContext(),loader);

                }



public void onResponse(JSONArray response) {
                JSONObject jsonObject = null;


                    for (int i = 0; i < response.length(); i++) {
                        try {
                            jsonObject = response.getJSONObject(i);

                            id_equipo = jsonObject.getString("idequipo");
                            id_usu = jsonObject.getString("idusuario");
                            nombre_equipo = jsonObject.getString("nombre_equipo");
                            cancha = jsonObject.getString("cancha");

                        } catch (JSONException e) {
                            Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
                            Log.v("Fallo_Json:", e.getMessage());
                        }
                    }

               // progressDialog.dismiss();
                loader.setVisibility(GONE);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
            }
Toast.makeText(getApplicationContext(),“Bienvenido”+nom\u usu+”,Toast.LENGTH\u SHORT.show();
Intent Intent=新的Intent(initiarsion.this,MainActivity.class);
意向。额外(“id”,id);
意向。额外支付(“名义上”,名义上);
意向。额外(“设备”,设备);
intent.putExtra(“密码”,password);
星触觉(意向);
如果(相等于(“S”)){
loader.setVisibility(可见);
getWindow().setFlags(WindowManager.LayoutParams.FLAG)不可触摸,
WindowManager.LayoutParams.FLAG(不可触摸);
añadipo x=新的añadipo();
x、 nombreCancha(id,getApplicationContext(),loader);
}
公共void onResponse(JSONArray响应){
JSONObject JSONObject=null;
对于(int i=0;i

给我一个错误:尝试调用空对象引用上的虚拟方法“void android.view.Window.clearFlags(int)”

在xml中使用进度条,因为ProgressDailog现在已取消定价

 <ProgressBar
        android:id="@+id/loader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@android:color/black"
        android:layout_gravity="center" />
然后在完成网络调用后清除标志

loader.visibility = GONE
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

您好,请仅在初始化视图后查看我的备注1 plscall getwindow()。在活动中仅在setContentView之后
loader.visibility = GONE
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);