Skip to main content
android "lazy load" listview tech
To Top
Start a New Topic » « Back to the Android Dev group
另外我在 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);