Home > DeveloperSection > Forums > How to slow down progressbar progression?
Andrew Watson
Andrew Watson

Total Post:39

Points:273
Posted on    November-16-2014 10:36 PM

 Android Multiple Threading  Loop 
Ratings:


 1 Reply(s)
 643  View(s)
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?



Chris S
Chris S

Total Post:48

Points:336
Posted on    November-17-2014 2:57 AM

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();

                }

                }

 };     


Don't want to miss updates? Please click the below button!

Follow MindStick