多线程中更新UI万能方法
2015-11-18 22:48
453 查看
/**
* 在任何线程通过该方法更新UI
* @param r
*/
public void updateUIFromAnyThread(Runnable r){
Handler handler = new Handler(Looper.getMainLooper());
handler.post(r);
}
以上方法其实原理还是在程序主线程中更新UI,通过Looper.getMainLooper()拿到主线程的Looper,作为构造参数得到的Handler就是可以在主线程分发异步消息的Handler了。
* 在任何线程通过该方法更新UI
* @param r
*/
public void updateUIFromAnyThread(Runnable r){
Handler handler = new Handler(Looper.getMainLooper());
handler.post(r);
}
以上方法其实原理还是在程序主线程中更新UI,通过Looper.getMainLooper()拿到主线程的Looper,作为构造参数得到的Handler就是可以在主线程分发异步消息的Handler了。
相关文章推荐
- UI第七天 UIScrollView UIPageControl
- 21.UIScrollView(滑动视图)和UIPageControl()
- Guide of Installing CUDA-7.5 on Ubuntu 14.04
- UITabBarController
- Android UI线程 HandlerThread 普通线程详解
- 芒果iOS开发UI课程第一节UIWindow
- iOS常见错误4-UITableView _configureCellForDisplay:forIndexPath:错误
- LeetCode OJ:Range Sum Query 2D - Immutable(区域和2D版本)
- UI_容器视图控制器
- UILabel显示HTML
- 本地通知 UILocalNotification
- leetcode 60:Permutation Sequence
- iOS开发:UIImage 图片处理:截图,缩放,设定大小,存储
- Elasticsearch DSL中Query与Filter的不同
- iOS开发——UI组件
- 初试MVVM框架之Vue.js - 列表渲染篇【南大软院大神养成计划】
- UI第七天:UIScrollView、UIPageContro
- Stack&Queue
- UIToolbar
- Machine Learning week 4 quiz: Neural Networks: Representation