wang_peng1 发表于 2013-2-7 09:59:49

线程的使用

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
页: [1]
查看完整版本: 线程的使用