我試圖開始一個新的活動「SMS.java」,如果我不響應我的計時器30secs內。 30秒後,新的動作應該開始。誰能幫我嗎???第5行類Timer延伸CountDownTimer .. 下面的代碼:如何在完成計時器後開始活動?
//TimerAct.java
public class TimerAct extends Activity
{
static TextView timeDisplay;
Timer t;
int length = 30000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.time);
timeDisplay = (TextView) findViewById(R.id.timer);
timeDisplay.setText("Time left: " + length/1000);
t = new Timer(length, 1000);
t.start();
View b1 = findViewById(R.id.abort);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
t.cancel();
finish();
}
});
}
}
//Timer.java
public class Timer extends CountDownTimer
{
public Timer(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
}
public void onTick(long millisUntilFinished)
{
TimerAct.timeDisplay.setText("Time left: " + millisUntilFinished/1000);
}
public void onFinish()
{
TimerAct.timeDisplay.setText("Time over!!!");
}
}
你真的需要張貼您的「定時器」類代碼。 – L7ColWinters 2012-01-30 13:41:22
@ L7ColWinters已發佈「定時器」類代碼..檢查出 – Nikunj 2012-01-30 13:53:43