0
這裏是我的自定義字段的paint方法:黑莓:在自定義字段你下載過圖片減緩VerticalFieldManager
protected void paint(Graphics graphics) {
new downloadImage();
Bitmap img = downloadImage.connectServerForImage(this.poster);
graphics.drawBitmap(0, 0, 100, 150, img, LEFT, TOP);
}
這裏是connectServerForImage方法:
public static Bitmap connectServerForImage(String url) {
HttpConnection httpConnection = null;
DataOutputStream httpDataOutput = null;
InputStream httpInput = null;
int rc;
Bitmap bitmp = null;
try {
httpConnection = (HttpConnection) Connector.open(url);
rc = httpConnection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
httpInput = httpConnection.openInputStream();
InputStream inp = httpInput;
byte[] b = IOUtilities.streamToBytes(inp);
EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
return hai.getBitmap();
} catch (Exception ex) {
System.out.println("URL Bitmap Error........" + ex.getMessage());
} finally {
try {
if (httpInput != null)
httpInput.close();
if (httpDataOutput != null)
httpDataOutput.close();
if (httpConnection != null)
httpConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return bitmp;
}
我把的多個實例,我自定義字段放入verticalfieldmanager,但圖像會減慢向下滾動。看起來好像每次滾動時都會再次運行paint方法,即使圖像已被下載。
我想我需要在另一個線程下載圖像?有人帶領我走向正確的方向。
3的補充 - 如果它已經開始不開始下載。 – 2011-12-27 06:53:07
謝謝我做了另一個線程下載。任何關於如何實施你所提出的建議的例子? – Adam 2012-01-01 05:34:04