android Stopwatch实例
Stopwatch 实例[java]
package net.baisoft.stopwatch;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements Runnable {
/**
* ��ǰ����ʱ��
*/
private long time = 0;
/**
* ��ʼʱ��
*/
private long startTime;
private Handler handler;
/**
* ������ʾʱ��
*/
private TextView timeView;
/**
* �����б���ʾ�ּ�ʱ��
*/
private ListView listView;
/**
* ��ʼ��ť
*/
private Button startButton;
/**
* ��ͣ��ť
*/
private Button pauseButton;
/**
* �ּǰ�ť
*/
private Button markButton;
/**
* ���ð�ť
*/
private Button resetButton;
/**
* �ּ�ʱ�����
*/
private List<Long> marks;
/**
* ���ĵ�ǰ״̬
* ��Ϊ�������С���ͣ��ֹͣ����״̬
*/
private int state = 0;
private static int STATE_RUNNING = 1;
private static int STATE_STOP = 0;
private static int STATE_PAUSE = 2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//��ȡ������Ϣ��ƫ�� ��
readEnvironment();
Toast.makeText(this, "�����Ѷ�ȡ", Toast.LENGTH_LONG).show();
//��ʼ��ť
startButton = (Button)findViewById(R.id.start);
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
onStartClick(view);
}
});
//��ͣ��ť
pauseButton = (Button)findViewById(R.id.pause);
pauseButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
onPauseClick(view);
}
});
//�ּǰ�ť
markButton = (Button) findViewById(R.id.mark);
markButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
onMarkClick(view);
}
});
//���ð�ť
resetButton = (Button) findViewById(R.id.reset);
resetButton.setOnClickListener(new OnClickListener() {
@Override
补充:移动开发 , Android ,