使用线程更新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(); }});