使用progessbar百分比下载图像

时间:2015-10-28 13:36:40

标签: android android-progressbar

您好,在下面的下载图片中显示progessbar为100但是完整的100%图片没有显示仍在下载而且没有显示。我希望在100%之后我想转移到活动。

但它需要时间来进行下一次活动。

的java

public class DownloadTask extends AsyncTask<Void, Void, String> {


        protected void onPreExecute() {
            super.onPreExecute();
            final DialogProgressBarRunnable progressDialog =
                    new DialogProgressBarRunnable(getActivity(), false, 2);
            progressDialog.show();
            // the dialog box shouldn't get cancelled when clicking outside it or pressing back button.
            progressDialog.setCanceledOnTouchOutside(false);
            progressDialog.setCancelable(false);

           // pd.setMessage("Downloading catalogue images.");
           // pd.show();

        }

        protected String doInBackground(Void... Params) {


            parsingObject = new ParsingForFinalImages(catid, responseJson);
           /* ConnectionDetector cd = new ConnectionDetector(getActivity().getBaseContext());
            Boolean isInternetPresent = cd.isConnectingToInternet();

            if (isInternetPresent==true)
            {

            }
            */

            // put your code here
            // JSON parsing begins here via the parsing class
            // Put this code in async task


            return "Success";

        }

        protected void onPostExecute(String result) {
            super.onPostExecute(result);
           // pd.hide();
          //  pd.dismiss();
            Intent intent = new Intent(getActivity(), ImageGallery.class);
            startActivity(intent);
        }
    }
    private class DialogProgressBarRunnable extends ProgressDialog implements
            Runnable {
        private boolean showSecondary;
        private int incrementAfter;

        public DialogProgressBarRunnable(Context context,
                                         boolean showSecondary, int incrementAfter) {
            super(context);
            setCancelable(true);
            setMessage(getString(R.string.download_message));
            setSecondaryProgress(0);
            setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            setMax(100);
            setProgress(0);
            this.showSecondary = showSecondary;
            this.incrementAfter = incrementAfter;
        }

        @Override
        public void show() {
            super.show();
            new Thread(this).start();
        }

        @Override
        public void run() {
            while (progress < 100) {
                progress++;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                // increment the first/second progress bar after every %
                progressBar();
            }
        }

        private void progressBar() {
            if (progress % incrementAfter == 0) {

                progressFirstBar();
            }
            if (showSecondary) {
                progressSecondaryBar();
            }
        }

        private void progressSecondaryBar() {
            while (secondaryProgress < 100) {
                secondaryProgress++;
                try {
                    Thread.sleep(50000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                handler.post(new Runnable() {

                    @Override
                    public void run() {

                        setSecondaryProgress(secondaryProgress);
                    }
                });
            }
        }

        private void progressFirstBar() {
            secondaryProgress = 0;
            handler.post(new Runnable() {

                @Override
                public void run() {
                    setProgress(progress);

                    if (progress == 100) {

                        dismiss();

                    }

                }
            });

        }
    }

1 个答案:

答案 0 :(得分:0)

class DownloadFileFromURL扩展了AsyncTask {

<select class="form-control" id="seleciona">
    <option value="0">Selecione</option>
    <option value="1">LAB 1</option>
    <option value="2">LAB 2</option>
    ...
</select>

<div id="calendar"></div>