刚刚开始想利用Timer去实现定时更新结果失败了。
之后使用了Handler去实现
View Code
1 package com.bw; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.os.Handler; 6 import android.widget.TextView; 7 8 public class TimeActivity extends Activity { 9 public TextView timeTextView; 10 11 private Handler handler = new Handler(); 12 private Runnable task = new Runnable() { 13 14 @Override 15 public void run() { 16 // TODO Auto-generated method stub 17 18 updateTimeTextView(); 19 } 20 }; 21 22 /** Called when the activity is first created. */ 23 @Override 24 public void onCreate(Bundle savedInstanceState) { 25 super.onCreate(savedInstanceState); 26 27 setContentView(R.layout.time); 28 29 timeTextView = findViewById(R.id.timeTextView); 30 31 handler.post(task); 32 33 } 34 35 36 private void updateTimeTextView() { 37 timeTextView.append("new"); 38 } 39 40 }