线程更新UI界面的4种方法
2013-04-10 10:28
253 查看
方法一:View.post(Runnable action)
方法二:Activity.runOnUiThread(Runnable action)
方法三:Handler
子线程调用Handler的sendMessage(Message message)方法发送消息
方法四:AsyncTask
public void onClick( View v ) { new Thread( new Runnable() { public void run() { // 耗时操作 doLongOperation(); myText.post(new Runnable() { myText.setText( 来自网络的信息); }); } }).start(); }
方法二:Activity.runOnUiThread(Runnable action)
public void onClick( View v ) { new Thread(new Runnable() { public void run() { // 耗时操作 doLongOperation(); Activity.runOnUiThread(new Runnable() { myText.setText( 来自网络的信息); }); } }).start(); }
方法三:Handler
子线程调用Handler的sendMessage(Message message)方法发送消息
mHandler = new Handler() { @Override public void handleMessage(Message msg) { // 更新界面 myText.setText(接收到的Message); } }; public class MyThread extends Thread { public void run() { // 耗时操作 doLongOperation(); Message msg = new Message(); mHandler.sendMessage(msg); } }
方法四:AsyncTask
// UI线程中执行 new DownloadImageTask().execute("");
相关文章推荐
- Android学习札记30:线程更新UI界面的4种方法
- Android在子线程更新UI的4种方法
- 总结4种线程中操作UI界面的方法
- Android 总结4种线程中操作UI界面的方法
- 非UI线程更新UI界面的各种方法小结
- Android 总结4种线程中操作UI界面的方法
- 在分线程更新主线程的Ui界面方法
- 总结4种线程中操作UI界面的方法
- 非UI线程更新UI界面的各种方法小结
- 总结4种线程中操作UI界面的方法
- 4种线程中操作UI界面的方法
- 总结4种线程中操作UI界面的方法
- Android进阶(二)-------总结4种线程中操作UI界面的方法
- 非UI线程更新UI界面的各种方法小结
- 总结4种线程中操作UI界面的方法
- 4种线程中访问Ui界面的方法
- java 总结4种线程中操作UI界面的方法
- Android在子线程中更新Activity中UI的方法
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- Android 刷新UI界面,线程间通讯方法总结,Android 自学之路