Activity.runOnUiThread 和 View.post()的讲解
来源:互联网 发布:懒人js 编辑:程序博客网 时间:2024/04/28 01:12
public class MainActivity extends Activity {
Button button;ImageView imageView;Context context;Runnable runnable;Bitmap bitmap;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context=this; //初始化控件 init(); //控件点击事件 weightOnClick();}private void init(){ button= (Button) findViewById(R.id.bt_download); imageView= (ImageView) findViewById(R.id.image); runnable=new Runnable() { @Override public void run() { if (bitmap!=null){ imageView.setImageBitmap(bitmap); } } };}private void weightOnClick(){ button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { HttpURLConnection httpURLConnection=null; InputStream inputStream=null; try { URL url=new URL("http://c.hiphotos.baidu.com/image/pic/item /c8ea15ce36d3d53984cf1e113e87e950342ab075.jpg"); httpURLConnection= (HttpURLConnection) url.openConnection(); inputStream=httpURLConnection.getInputStream(); bitmap= BitmapFactory.decodeStream(inputStream); // ((Activity)context).runOnUiThread(runnable); imageView.post(runnable); inputStream.close(); } catch (Exception e) { e.printStackTrace(); }finally { httpURLConnection.disconnect(); } } }).start(); } });}
}
1 0
- Activity.runOnUiThread 和 View.post()的讲解
- 跟进View的常见周期回调以及View.post和Activity.runOnUiThread
- runOnUiThread 、Handler.post、View.post之间的区别
- view.post,handler.runonUiThread详解
- handler Activity.runOnUIThread(Runnable) View.Post(Runnable) View.PostDelayed(Runnabe,lon
- Handler简单分析-runOnUiThread,view.post()
- Android Activity.runOnUiThread() 和 Handler
- Handler、Message 和 Activity.runOnUiThread()
- android Activity类的runOnUiThread
- Activity类的runOnUiThread方法
- activity的runOnUiThread方法使用
- android多线程handler+runOnUithread+view.post+handler.post
- android多线程handler+runOnUithread+view.post+handler.post 2013-
- Android多线程之handler+runOnUithread+view.post+handler.post
- 2个更新UI的方法--activity.runOnUiThread及handler.post
- android.view.ViewRoot$CalledFromWrongThreadException 异常的解决方案Activity类runOnUiThread方法
- Activity中runOnUiThread方法的使用
- Activity类的runOnUiThread更新UI
- 关于Keil5移植SDIO不成功的问题
- 模型-视图 教程
- Scala 数组(1)
- 在ubuntu下安装jdk
- 经验与教训: 禁止在linux编译目录下用Windows方式备份文件;禁止在linux编译目录备份成以.cpp结尾的文件名
- Activity.runOnUiThread 和 View.post()的讲解
- 设计模式—工厂模式
- 带展开更多收起更多的可扩展的ListView
- python scrapy使用
- php7 使用mysql nginx配置
- java设计模式之单例模式
- C#笔记 跨线程操作控件
- Mysql查询in和exists的效率
- iOS开发-推送-第三方推送前期准备工作