public class CountdownTimerActivity extends Activity {
private TimeCount time;
private Button checking;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
time = new TimeCount(60000, 1000);//構造CountDownTimer對象
checking = (Button) findViewById(R.id.button1);
checking.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
time.start();//開始計時
}
});
}
/* 定義一個倒計時的內部類 */
class TimeCount extends CountDownTimer {
public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);//參數依次為總時長,和計時的時間間隔
}
@Override
public void onFinish() {//計時完畢時觸發
checking.setText("重新驗證");
checking.setClickable(true);
}
@Override
public void onTick(long millisUntilFinished){//計時過程顯示
checking.setClickable(false);
checking.setText(millisUntilFinished /1000+"秒");
}
}
想要獲得成功,首先要自己相信自己,再者要贏得周圍朋友的信任!