0

So probably pretty easy but I can figure this out. Basically I want to set up a Progress Bar to increase by 1 for 10 seconds and then send the user to another activity. Can anyone show me how to do this?

Adariel Lzinski
  • 1,031
  • 2
  • 19
  • 43
  • What have you tried so far? Show us something! Google for "android timer" or, even better, for "android handler postdelayed" – SimonSays Jul 23 '13 at 17:18
  • 1
    Keep a reference of the `ProgressBar` instance you want to update and `setProgress()` [when `Timer` ticks](http://stackoverflow.com/questions/1877417/how-to-set-a-timer-in-android). What exactly you try? – m0skit0 Jul 23 '13 at 17:19

1 Answers1

0

Since Runnable object can be reused, simplest approach is recursively call on Handler until maximum is reached, also you can count how many times you had recursive call.

mProgressBar.setMax(10);
mProgressBar.getHandler().post(new Runnable(){

            @Override
            public void run() {
                if(mProgressBar.getProgress()<mProgressBar.getMax()){
                    mProgressBarincrementProgressBy(1);// you specify the progress using this method or setProgres()
                    mProgressBar.getHandler().postDelayed(this, 1000);
                }
            }},1000);

:)

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148