main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/clockText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <AnalogClock android:id="@+id/analogClock" android:layout_width="fill_parent" android:layout_height="wrap_content" ></AnalogClock> </LinearLayout> ClockActivity.java package com.itxinke.www; import java.util.Calendar; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.widget.TextView; public class ClockActivity extends Activity { /** Called when the activity is first created. */ protected static final int GUINOTIFIER = 0x1234; private TextView clockText; private Handler handler; private Thread clockThread; private int mHours; private int mMinutes; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); clockText = (TextView)findViewById(R.id.clockText); handler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub clockText.setText(mHours + ":" + mMinutes); super.handleMessage(msg); } }; clockThread = new ClockThread(); clockThread.start(); } private class ClockThread extends Thread { @Override public void run() { // TODO Auto-generated method stub super.run(); try { do { long time = System.currentTimeMillis(); final Calendar mCalendar = Calendar.getInstance(); mCalendar.setTimeInMillis(time); mHours = mCalendar.get(Calendar.HOUR); mMinutes = mCalendar.get(Calendar.MINUTE); Thread.sleep(1000); Message message = new Message(); message.what = ClockActivity.GUINOTIFIER; ClockActivity.this.handler.sendMessage(message); } while(ClockActivity.ClockThread.interrupted() == false); }catch(Exception e) { e.printStackTrace(); } } } } 效果图: