android秒表计时代码
package com.TestDemo; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.widget.TextView; public class TestDemo extends Activity { /** Called when the activity is first created. */ public TimerHandler timerHandler; public Timer timer; public MyTimerTask task; public int m_nTime = 0;//计时 public TextView mtimeshow=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mtimeshow=(TextView)findViewById(R.id.time_show); timer=new Timer(true); task=new MyTimerTask(this); timer.schedule(task, 0, 1000 ); timerHandler = new TimerHandler(this); bindService(null, null, m_nTime); } private class MyTimerTask extends TimerTask { private TestDemo me; public MyTimerTask(TestDemo p) { me=p; } public void run() { me.m_nTime++; me.timerHandler.sendEmptyMessage(0); } } public class TimerHandler extends Handler { private TestDemo me; public TimerHandler(TestDemo m) { me=m; } @Override public void handleMessage(Message msg) { me.mtimeshow.setText(me.m_nTime+""); } } }