使用进度条百分比的截击请求

时间:2019-06-17 10:59:32

标签: android progress-bar

我在警报对话框中实现了水平进度条(我使用这种方式是因为不赞成使用进度对话框)。我想在进度请求成功之前使用带有百分比的进度条。这是我的百分比进度栏的代码

ubmitPredictPlant.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

                AlertDialog.Builder myDialogBuilder = new AlertDialog.Builder(getActivity());
                View ProgressView = getLayoutInflater().inflate(R.layout.layout_loading_dialog,
                        null);
                predictProgress=(ProgressBar)ProgressView.findViewById(R.id.progressbarPredict);
                progressNotif = (TextView) ProgressView.findViewById(R.id.progressNotif);
                phasePredict = (TextView) ProgressView.findViewById(R.id.phasePredict);

                myDialogBuilder.setView(ProgressView);
                myDialogBuilder.create().show();

                new Thread(new Runnable() {
                    public void run() {
                        while (progressStatus < 100) {
                            progressStatus += 1;
                            // Update the progress bar and display the
                            //current value in the text view
                            handler.post(new Runnable() {
                                public void run() {
                                    predictProgress.setProgress(progressStatus);
                                    progressNotif.setText(progressStatus+"/"+predictProgress.getMax());
                                    if (progressStatus <= 25)
                                    {
                                        phasePredict.setText("Phase :"+"Phase 1");
                                    }
                                    else if (progressStatus <= 50){
                                        phasePredict.setText("Phase :"+"Phase 2");
                                    }
                                    else if (progressStatus <= 75){
                                        phasePredict.setText("Phase :"+"Phase 3");
                                    }
                                    else{
                                        phasePredict.setText("Phase :"+"Phase 4");
                                    }


                                }
                            });
                            try {
                                // Sleep for 200 milliseconds.
                                Thread.sleep(200);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }).start();

但是如果我对排球的请求成功,如何使其达到100%,这就是排球请求的示例

JsonObjectRequest predictRequest = new JsonObjectRequest(Request.Method.POST, url,jsonObject, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            //100% is in here
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

所以问题是如何结合进度条上的线程和齐射上的请求?

0 个答案:

没有答案