日期:2014-05-20 浏览次数:20654 次
public class mainActivity extends Activity { Button button; Button button2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.btn1); button2 = (Button) findViewById(R.id.btn2); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { timer = new Timer(); timer.schedule(task, 1000, 1000); } }); button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { 这里该怎么写让他完全停止 再次点击开始的时候不报错 } }); } Timer timer; TimerTask task = new TimerTask() { @Override public void run() { System.out.println("a"); } }; }