Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
700 views
in Technique[技术] by (71.8m points)

progress bar - 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!

question from:https://stackoverflow.com/questions/10241633/android-progressbar-countdown

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...