2017-06-01 70 views
-3

我想打一个应用程序,可以2秒如何每秒重置System.currentTimeMillis()?

final Handler timerHandler = new Handler(); 
       Runnable timerRunnable = new Runnable() { 
        @Override 
        public void run() { 
         long millis = System.currentTimeMillis() - startTime; 
         int seconds = (int) (millis/1000); 
         int decis = (int) ((millis % 1000)/10); 

         TimerBox.setText(String.format("Time: %d.%02d", seconds, decis)); 
         Tx.setText(""+counting); 
         timerHandler.postDelayed(this, 10); 
         if(seconds == 2){ 
          counting = 1; 
          seconds = 0; 
          decis = 0; 
         } 
        } 
       }; 

内设置一个变量,这不是我的代码,即时通讯在Android Studio中

回答

-1
new Thread(new Runnable() 
    { 
     @Override 
     public void run() 
     { 
      while(true) 
      { 
       time = System.currentTimeMillis(); 
       if(time>=2000) 
       { 
        time=0; 
        //do things here 
       } 
      } 
     } 
    }).start(); 

这样curently新的就可以知道,当两个秒通过