上次使用Chronometer这个控件实现了秒表,这次使用handler实现秒表(完结)

package com.sun;


import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.SeekBar;
import android.widget.TextView;

public class MainActivity extends Activity  {
    TextView mTrackingText;
    Handler  handler=new Handler(){
    public void handleMessage(android.os.Message msg) {
    	switch (msg.what) {
			case 1 :
				String  s=getMin();
				String  s1=getMan();
				mTrackingText.setText((s.length()<2?"0"+s:s)+":"+(s1.length()<2?"0"+s1:s1)+"     "
						+"[email protected]");
				 Message  msg1=new Message();
			        msg1.what=1;
			        handler.sendMessageDelayed(msg1, 1000);
				break;

			default :
				break;
		}
    }
   private String getMan() {
		// TODO Auto-generated method stub
		return String.valueOf(count%60);
	}
int  count;
	private String getMin() {
		// TODO Auto-generated method stub
		count ++;
		return String.valueOf(count/60);
	};	
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        mTrackingText=(TextView) findViewById(R.id.tracking);
        mTrackingText.setText("00:00");
        Message  msg=new Message();
        msg.what=1;
        handler.sendMessageDelayed(msg, 1000);
    }

 
}




    




你可能感兴趣的:(android高级)