Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProgressBar countdown

I'm making a quiz for Android and I want a limited time to answer every question. So I want to display a ProgressBar under the answers that counts down from, for example, 5 to 0 (seconds). And when it reaches zero I want to do some stuff. I have the quiz and everything working, I just want to add the ProgressBar.

Thanks in advance!

like image 278
simtaxman Avatar asked Apr 20 '12 06:04

simtaxman


People also ask

How do I set a countdown clock on my Android?

we can set count down time after completion of time it will stop and get 0 values. onTick(long millisUntilFinished ) - In this method we have to pass countdown mill seconds after done countdown it will stop Ticking. onFinish() - After finish ticking, if you want to call any methods or callbacks we can do in onFinish().


1 Answers

you can use countdown timer in android .

Here is one Example you can Refer Click Here

you can use below ProgressBar in your Activity.

   <ProgressBar      android:id="@+id/progressbar"     style="@android:style/Widget.ProgressBar.Horizontal"     android:max="100"     android:progress="0"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_above="@+id/bottom_header_relativelayout"     /> 

Use CountDownTimer Like Below code in your Activity.

ProgressBar mProgressBar; CountDownTimer mCountDownTimer; int i=0;  mProgressBar=(ProgressBar)findViewById(R.id.progressbar); mProgressBar.setProgress(i);    mCountDownTimer=new CountDownTimer(5000,1000) {          @Override         public void onTick(long millisUntilFinished) {             Log.v("Log_tag", "Tick of Progress"+ i+ millisUntilFinished);             i++;             mProgressBar.setProgress((int)i*100/(5000/1000));          }          @Override         public void onFinish() {         //Do what you want              i++;             mProgressBar.setProgress(100);         }     };     mCountDownTimer.start(); 
like image 189
Herry Avatar answered Oct 16 '22 08:10

Herry