public class time extends Activity implements Runnable{
//定义要使用的类对象
private TextView showTime;//显示进程时钟的TextView
AnalogClock myClock;//模拟时钟
DigitalClock myDigClock;//数字时钟
private final int msg_Key=0x1234;//发送消息内容
public Handler myHandler;//发送处理消息的类
public Calendar myCalendar;//日历类
private int my_Hour,my_Minute,my_Second;//时分秒
private Thread myT;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//导入主屏布局main.xml
setContentView(R.layout.main);
//从xml中获取模拟字时钟UI对象
myClock=(AnalogClock)findViewById(R.id.Clock);
//从xml中获取数字字时钟UI对象
myDigClock=(DigitalClock)findViewById(R.id.DigitalClock01);
//从xml中获取TextView UI对象
showTime=(TextView)findViewById(R.id.TextView_showTime);
//通过Handler来接收进程所传递的信息并更新TextView
myHandler=new Handler(){
@Override
public void handleMessage(Message msg){
//这是处理信息的反法
super.handleMessage(msg);
switch (msg.what){
case msg_Key:
//在这处理要TextView对象Show时间事件
showTime.setText(my_Hour+":"+my_Minute+":"+my_Second);
break;
default:break;
}