如何通过在android中使用线程重置进度轮?

时间:2013-09-27 08:44:42

标签: android multithreading

我正在使用两个进度轮。在完成进度后,如何重置第一个进度轮并启动第二个进度轮? 我的代码:

        final Runnable r = new Runnable() {
        public void run() {
            running = true;

            while(progress<361) {
                pw_two.incrementProgress();
                progress++;
                try {
                    Thread.sleep(5);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
                progress = 0;

            while(progress<361) {
                pw_one.incrementProgress();
                progress++;
                try {
                    Thread.sleep(5);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
                progress = 0;

            running = false;

        }
    };

点击按钮即可重置。但我需要在线程完成后重置。

Button increment = (Button) findViewById(R.id.btn_increment);
increment.setOnClickListener(new OnClickListener() {
 public void onClick(View v) {
 if(!running) {
       pw_two.resetCount();
   pw_one.resetCount();
   Thread s = new Thread(r);
   s.start();

  }
    }
 });

1 个答案:

答案 0 :(得分:0)

使用此代码..我也使用自定义progresswheel ..

if(pw_one.progress == 360) {  //  progress is valariable from Progresswheel class
pw_one.resetCount();
// then start the next one  
}

note : https://github.com/Todd-Davies/ProgressWheel
i just use this above link code..