URLから画像を読み込んでリストフィールドで再生できません
ImageLoader
クラス
public class Util_ImageLoader {
public static Bitmap getImageFromUrl(String url) {
Bitmap bitmap = null;
try {
String bitmapData = getDataFromUrl(url);
bitmap = Bitmap.createBitmapFromBytes(bitmapData.getBytes(), 0,
bitmapData.length(), 1);
} catch (Exception e1) {
e1.printStackTrace();
}
return bitmap;
}
private static String getDataFromUrl(String url) {
StringBuffer b = new StringBuffer();
InputStream is = null;
HttpConnection c = null;
long len = 0;
int ch = 0;
try {
c = (HttpConnection) Connector.open(url);
is = c.openInputStream();
len = c.getLength();
if (len != -1) {
for (int i = 0; i < len; i++)
if ((ch = is.read()) != -1) {
b.append((char) ch);
}
} else {
while ((ch = is.read()) != -1) {
len = is.available();
b.append((char) ch);
}
}
is.close();
c.close();
} catch (IOException e) {
e.printStackTrace();
}
return b.toString();
}
}
ListField
クラス
image = new BitmapField(Util_ImageLoader.getImageFromUrl(
"http://www.orientaldaily.com.my/images/articles/4_APRIL_BLACK_copy.jpg"),
Field.FIELD_HCENTER | Field.FIELD_VCENTER);
row.add(image);
field = getField(3);
layoutChild(field, 100, 80);
setPositionChild(field, getPreferredWidth() - 105, 5);