HOW TO SLOW DOWN PROGRESSBAR PROGRESSION?

Andrew Watson

Total Post:39

Points:273
Posted by  Andrew Watson
 1070  View(s)
Ratings:
Rate this:

I am using this code here to loop and update progress on a custom progressbar.

class MyThreadRunner implements Runnable {

        // @Override

     int count = 0;

        public void run() {

            try {

            while (count < 90) {

                Thread.sleep(10);

                count += 1;

                 progressBar.setProgress(count);

                 progressBar.setText(count + "%");

            }

                } catch (InterruptedException e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

                }

                }

 };

When it gets closer towards the end I want it to start slowing down,is this possible without have to make another while loop?

  1. Chris S

    Post:48

    Points:336
    Re: How to slow down progressbar progression?

    Why not just change the sleep time for values over 90?

        class MyThreadRunner implements Runnable {

            // @Override

         int count = 0;

            public void run() {

                try {

                while (count < 100) {

                    //500 is half a second...

                    int sleepTime = count < 90 ? 10 : 500;

                    Thread.sleep(sleepTime);

                    count += 1;

                     progressBar.setProgress(count);

                     progressBar.setText(count + "%");

                }

                    } catch (InterruptedException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                    }

                    }

     };     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!