我正嘗試創建全屏時鐘。我設法將文本設置爲幾小時,幾分鐘和幾秒鐘。那麼,但是當我啓動應用程序,它顯示的時間,但用戶界面不更新......我不知道該怎麼做,我讀了這個教程,但我不明白它...任何人都可以解釋我如何consaline更新用戶界面?Android上創建時鐘未更新
public class Clock1Activity extends Activity {
/** Called when the activity is first created. */
private Timer timer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView txtHour = (TextView)findViewById(R.id.TxtHour);
final TextView txtMinutes = (TextView)findViewById(R.id.TxtMinute);
final TextView txtSeconds = (TextView)findViewById(R.id.TxtSeconds);
final TextView txtMilliseconds = (TextView)findViewById(R.id.TxtMilliseconds);
final Integer hora = new Integer(Calendar.HOUR_OF_DAY);
final Integer minutos = new Integer(Calendar.MINUTE);
final Integer segundos = new Integer(Calendar.SECOND);
final Long milisegundos = new Long (System.currentTimeMillis());
timer = new Timer("DigitalClock");
Calendar calendar = Calendar.getInstance();
// Get the Current Time
final Runnable updateTask = new Runnable() {
public void run() {
/** txtHour.setText(hora.toString());
txtMinutes.setText(minutos.toString());
txtSeconds.setText(segundos.toString()); */
txtMilliseconds.setText(milisegundos.toString());
Toast toast1 = Toast.makeText(getApplicationContext(), milisegundos.toString(), Toast.LENGTH_SHORT);
toast1.show();
}
};
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(updateTask);
}
}, 1, 1000);
}
}
只要告訴我如何完成它更新UI,請...
如果你想有人解釋... thenyou應該表現出你的代碼的某些部分也...使用此提出改進意見 – 5hssba 2012-04-24 15:50:02