- public class timerTask extends Activity{
- private int recLen = 11;
- private TextView txtView;
- Timer timer = new Timer();
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.timertask);
- txtView = (TextView)findViewById(R.id.txttime);
- timer.schedule(task, 1000, 1000); // timeTask
- }
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- runOnUiThread(new Runnable() { // UI thread
- @Override
- public void run() {
- recLen--;
- txtView.setText(""+recLen);
- if(recLen < 0){
- timer.cancel();
- txtView.setVisibility(View.GONE);
- }
- }
- });
- }
- };
- }
倒计时五种方法,方法一:Timer与TimerTask(Java实现)
最新推荐文章于 2022-09-17 15:15:08 发布