final Runnable r = new Runnable()
{
public void run()
{
tv.append("Hello World");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);
Thread thread = new Thread()
{
@Override
public void run() { try {
while(true) {
sleep(1000);
handler.post(r);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
2.多线程图片
class DownloadImage extends AsyncTask<Void, Void, Drawable>{
@Override
protected Drawable doInBackground(Void... params) {
return Util.getImageFromURL(imageURL);
}
@Override
protected void onPostExecute( Drawable d ) {
getImageIcon().setImageDrawable(d);
}
}
new DownloadImage().execute();
http://developer.android.com/intl/zh-CN/reference/android/os/AsyncTask.html