Android 动态的显示时间
怎么才能动态的实现时间呢?也许刚入行的你不懂。如果不懂得话,请看代码(代码是最好的老师)。大笑
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView=(TextView)findViewById(R.id.time);
handler=newHandler(){
publicvoidhandleMessage(Messagemsg){
textView.setText((String)msg.obj);
}
};
newThread(this).start();
}
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
try{
while(true){
SimpleDateFormatsdf=newSimpleDateFormat("yyyy年MM月dd日HH:mm:ss");
Stringstr=sdf.format(newDate());
handler.sendMessage(handler.obtainMessage(100,str));
Thread.sleep(1000);
}
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
由上面的代码可以看出,这是一个多线程。实时获取系统的时间后,就更新数据。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短