import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class TestTimer extends Activity {
private Button btnStart;
private Button btnStop;
private Button btnReset;
private TextView tvCounter;
private CheckBox cb ;
private long count = 0;
private boolean run = false;
private Handler handler = new Handler();
private Runnable task = new Runnable() {
public void run() {
// TODO Auto-generated method stub
SystemClock.sleep(3000);
Toast.makeText(TestTimer.this, "关闭打钩", Toast.LENGTH_SHORT).show();
// handler.post(task);
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnStart = (Button) findViewById(R.id.Button01);
btnStop = (Button) findViewById(R.id.Button02);
btnReset = (Button) findViewById(R.id.Button03);
tvCounter = (TextView) findViewById(R.id.counter);
cb = (CheckBox)findViewById(R.id.cb);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(arg1){
Toast.makeText(TestTimer.this, "开启打钩", Toast.LENGTH_SHORT).show();
}else{
cb.setChecked(false);
handler.post(task);
}
}
});
}
}