android简单倒计时

public class TimerActivity extends Activity {
	/** Called when the activity is first created. */
	
	private TextView timerView ;
	private MyTimer timer;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		timerView = (TextView)findViewById(R.id.time);
		timer = new MyTimer(50000, 1000);
		final Button timerButton = (Button)findViewById(R.id.start_button);
		timerButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				timer.start();
			}
		});
		
	}

	class MyTimer extends CountDownTimer {

		public MyTimer(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}

		@Override
		public void onFinish() {
			timerView.setText("结束了...");
		}

		@Override
		public void onTick(long millisUntilFinished) {
			Log.i("millisUntilFinished:", String.valueOf(millisUntilFinished));
			timerView.setText(""+millisUntilFinished/1000);
		}

	}

}

你可能感兴趣的:(android)