How to slow down progressbar progression?

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?

Last updated:11/17/2014 2:57:44 AM

1 Answers

Anonymous User
Anonymous User

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