Skip to main content

Home/ Android Dev/ [Disccuss] lasy load of images in ListView
Vincent Tsao

[Disccuss] lasy load of images in ListView - 2 views

android "lazy load" listview tech

started by Vincent Tsao on 23 Mar 10
  • Vincent Tsao
     
    altchen share了一个解决方案: http://groups.diigo.com/group/android_related/content/android-how-do-i-do-a-lazy-load-of-images-in-listview-stack-overflow-1423027

    另外我在 Android developer邮件列表中看到了另外一个解决方案,看起来也大同小异了,代码如下:

    public class imageloader implements Runnable{

    private String ss;
    //private View v;
    //private View v2;
    private ImageView im;

    public imageloader(String s, ImageView im) {
    this.ss=s;
    //this.v2=v2;
    this.im=im;
    Thread thread = new Thread(this);
    thread.start();
    }
    public void run(){
    try {
    // URL url = new URL(ss);
    // URLConnection conn = url.openConnection();
    // conn.connect();
    HttpGet httpRequest = null;
    httpRequest = new HttpGet(ss);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = (HttpResponse)
    httpclient.execute(httpRequest);
    HttpEntity entity = response.getEntity();
    BufferedHttpEntity bufHttpEntity = new
    BufferedHttpEntity(entity);
    InputStream is = bufHttpEntity.getContent();
    // BufferedInputStream bis = new
    BufferedInputStream(is);
    Bitmap bm = BitmapFactory.decodeStream(is);
    Log.d("img","img");
    // bis.close();
    is.close();
    im.setImageBitmap(bm);
    // im.forceLayout();
    // v2.postInvalidate();
    // v2.requestLayout();
    } catch (Exception t) {
    Log.e("bitmap url", "Exception in updateStatus()", t);
    //goBlooey(t);
    // throw new RuntimeException(t);
  • Vincent Tsao
     
    ah~ ,看来Diigo groups展示代码的样式得改进了.....

To Top

Start a New Topic » « Back to the Android Dev group