我正在使用标签界面和片段在每个标签上加载不同的JSON点击。
我正在下载从JSON解析的图像,但问题是每次触摸屏时调试器都会显示大量的消息
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: status 200
W/ImageDownloader: Error downloading image from null
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: status 200
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: status 200
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: status 200
W/ImageDownloader: Error downloading image from null
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: status 200
我明白这是系统写的,是在课堂上编写的,但这不应该运行太多次,它应该只在第一次点击时下载一次而不是每次触摸屏幕
我在片段 onViewCreated 中调用JSON类,该类扩展 AsyncTask 。我尝试从此类中的onPostExecute和JSON类中的不同位置加载它,但看起来它一直在尝试下载图像,但是文本正站在原地。碰巧图像在一个imageView中发生变化。
我正在尝试从customlistadapter下载启动ImageDownloaderTask类的图像。如果我将此下载移动到其他地方
,则会被调用太多次new ImageDownloaderTask(holder.imageView).execute(newsItem.getImage());
这是我的代码的一部分,它以JSON
生成它 private Bitmap downloadBitmap(String url) {
HttpURLConnection urlConnection = null;
try {
URL uri = new URL(url);
urlConnection = (HttpURLConnection) uri.openConnection();
int statusCode = urlConnection.getResponseCode();
System.out.println("status "+statusCode);
InputStream inputStream = urlConnection.getInputStream();
if (inputStream != null) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
}
} catch (Exception e) {
if (urlConnection != null) {
urlConnection.disconnect();
}
Log.w("ImageDownloader", "Error downloading image from " + url);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
return null;
}