WEB开发网
开发学院手机开发Android 开发 Android中Handler的使用 阅读

Android中Handler的使用

 2012-12-20 15:20:48 来源:WEB开发网   
核心提示:public class TimerActivity extends Activity { private int count = 1; private Handler handler=new Handler(){ public void handleMessage(android.os.Message msg)

public class TimerActivity extends Activity {
private int count = 1;
private Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 1:
updateTitle();
break;

default:
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Timer timer=new Timer();
timer.scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {
Message message=new Message();
message.what=1;
handler.sendMessage(message);
}
}, 1000,5000);
}


protected void updateTitle() {
setTitle("Welcome to my blog" + count++);
}
}

上一页  1 2 

Tags:Android Handler 使用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接