首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

运用线程更新UI

2012-09-03 
使用线程更新UI?public void onClick(View v){new Thread( new Runnable(){public void run(){Bitmap b

使用线程更新UI

?

public void onClick(View v){ new Thread( new Runnable(){ public void run(){ Bitmap b = loadImageFromNetwork(); mImageView.setImageBitmap(b); } }).start();}?

private Thread thread = new Thread() { @Override public void run() { boolean running = true; while (running) { try { settime.sendMessage(settime.obtainMessage()); Thread.sleep(1000); } catch (InterruptedException e) { Log.d("Thread", "Exception"); running =false; } } }};

private Handler settime = new Handler() { Time t = new Time(); String time = new String(); @Override public void handleMessage(Message msg) { super.handleMessage(msg); t.setToNow(); tv_time.setText(time.format("%2d:%2d %d", t.hour, t.minute, t.second)); }};

b_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { thread.interrupt(); }});

热点排行