Android高手进阶教程 Android Handler的使用
2010-05-08 18:13:00 来源:WEB开发网核心提示:private Handler mHandler = new Handler(){public void handleMessage(Message msg) {switch (msg.what) {case 1:updateTitle();break;}};};public void onCreate(Bundle
private Handler mHandler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
updateTitle();
break;
}
};
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTask(), 1, 5000);
}
private class MyTask extends TimerTask{
@Override
public void run() {
Message message = new Message();
message.what = 1;
mHandler.sendMessage(message);
}
}
public void updateTitle(){
setTitle("Welcome to Mr Wei's blog " + title);
title ++;
}
}
下面我们看一下效果图:
更多精彩
赞助商链接