gpt4 book ai didi

java - 如何使用 Android 通用图像加载器使用 ImageLoad

转载 作者:行者123 更新时间:2023-12-01 13:53:22 26 4
gpt4 key购买 nike

关于我之前的主题HERE我已成功在 ListView 中显示图像。原来是在显示图像的过程中没有使用async,感觉listview很重。然后我尝试使用库 Android Universal Image Loader 。在我的库使用中仍然有点困惑尝试组合和替换我以前使用的 ImageLoader 库。

我在 Activity 和适配器中放入了 onCreate :

File cacheDir = StorageUtils.getCacheDirectory(this.getApplicationContext());
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this.getApplicationContext())
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null)
.threadPoolSize(3) // default
.threadPriority(Thread.NORM_PRIORITY - 1) // default
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024)
.memoryCacheSizePercentage(13) // default
.discCache(new UnlimitedDiscCache(cacheDir)) // default
.discCacheSize(50 * 1024 * 1024)
.discCacheFileCount(100)
.imageDownloader(new BaseImageDownloader(this.getApplicationContext())) // default
.build();
ImageLoader.getInstance().init(config);

在我的循环中(在 onPostExecute 中):

for (int i = 0; i < allData.length(); i++) {

JSONObject c = allData.getJSONObject(i);

// Storing each json item in variable
String id = c.getString(Constants.TAG_MenuID);
String title = c.getString(Constants.TAG_Title);
String post = c.getString(Constants.TAG_Post);
String image = c.getString(Constants.TAG_Image);

BeritaBean mb = new BeritaBean();
mb.setID(id);
mb.setTitle(title);
mb.setPost(post);
mb.setImg(image);

AmbilDataBean.add(mb);
}
adapter.setItem(AmbilDataBean);

然后我也更改了以前的适配器(使用ImageLoader类):

public View getView(int position, View convertView, ViewGroup parent) {

View v = inflater.inflate(R.layout.list_row, null);

ImageView img = (ImageView) v.findViewById(R.id.image);
TextView judul = (TextView) v.findViewById(R.id.judul);
TextView tanggal = (TextView) v.findViewById(R.id.tanggal);
TextView isi = (TextView) v.findViewById(R.id.isi);

BeritaBean obj = (BeritaBean) getItem(position);

judul.setText(obj.getTitle());
tanggal.setText(obj.getCreated());
isi.setText(obj.getPost());

try {
String urlImage = obj.getImg();
if(urlImage.length() > 0){
img.setTag(urlImage);
imageLoader.DisplayImage(urlImage, img);
}
} catch (Exception e) {

}
return v;
}

成为(使用通用图像加载器)部分:

try {
String urlImage = obj.getImg();
if(urlImage.length() > 0){
img.setTag(urlImage);
imageLoader.displayImage(urlImage, img);
}
} catch (Exception e) {

}

但是在我的应用程序运行后,静态图像无法显示。这个图书馆缺少什么设置吗?请帮忙

最佳答案

这似乎有点矫枉过正 - 对于一个使用异步加载并很好地处理 ListView 的优秀库,请查看 koush 的(众所周知的开发)UrlImageViewHelper lib on github

关于java - 如何使用 Android 通用图像加载器使用 ImageLoad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19791504/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com