简体   繁体   English

创建进度条以设置计时器

[英]Create Progress Bar to set timer

In my Math test application, I want to set 10s for a question using a progressing bar. 在我的数学测试应用程序中,我想使用进度条为问题设置10分。 Here is my code: 这是我的代码:

public class Question extends Activity {
private boolean enoughTime = true;
    private ProgressBar progressBar;
    int progressStatus = 0;
    private Handler handler = new Handler();
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    createQuestionView();
    new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                while (progressStatus < 1000){
                    progressStatus += 1;
                    enoughTime = true;
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                        // TODO Auto-generated method stub
                            progressBar.setProgress(progressStatus);
                        }
                    });
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                if (progressStatus >= 500){
                    enoughTime = false;
                }
            }
        }).start();
   while (enoughTime){
      DoSomeThing();
   }
   while (!enoughTime){
      DisplaySocre();
   }

It doesn't work. 没用 I think my problem is about while loop but don't know how to fix it. 我认为我的问题与while循环有关,但不知道如何解决。 Any recommend? 有什么建议吗? Thank you so much. 非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM