2015-09-06 18 views
0

我需要在RelativeLayout中進行時間控制,也就是說「此時從此活動開始,我希望應用此方法」。我嘗試在SurfaceView中使用:RelativeLayout中的時間計數

long time; 
time = System.currentTimeMillis(); 
... 
public static long getCurrentTimeFromStart() { 
    long current = System.currentTimeMillis(); 
    return current-time; 
} 
... 
if(getCurrentTimeFromStart() > timeChoosen){ 
method();} 

但是這在RelativeLayout中不起作用。所以我問你是否有另一種方法需要時間控制。

在此先感謝!

回答

0

您可以使用CountDownTimer類來實現您的任務。您可以在onFinish()方法中調用您想要的方法,該方法將在倒數計時器結束後觸發。

希望這會有所幫助。