これは、画像をロードするための単純な関数です。Android 2.2 では問題なく動作しますが、Android 4 の画像をダウンロードして表示することはありません。これは作成時のコードです:
Bitmap bitmap = DownloadImage(weather.icon);
holder.imgIcon.setImageBitmap(bitmap);
ホルダーは正常に動作します/これが機能です:
private InputStream OpenHttpConnection(String urlString) throws IOException {
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (Exception ex) {
throw new IOException("Error connecting");
}
return in;
}
private Bitmap DownloadImage(String URL) {
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
BufferedInputStream bis = new BufferedInputStream(in, 8190);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
byte[] imageData = baf.toByteArray();
bitmap = BitmapFactory.decodeByteArray(imageData, 0,
imageData.length);
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
誰か助けてくれませんか、疲れました。ありがとう