[英]How to use ImageLoad using Android Universal Image Loader
On the topic of my previous HERE I have managed to display the image in my listview. 在我以前的话题这里我设法在我的列表视图来显示图像。 It turned out to not be using async in the process of displaying images, I felt heavy listview. 事实证明,在显示图像的过程中没有使用异步,我感到列表视图很重。 I then tried to use the library Android Universal Image Loader . 然后,我尝试使用库Android Universal Image Loader 。 In my library usage is still a little confused trying to combine and replace the previous use ImageLoader library I use. 在我的库中,尝试合并并替换以前使用的ImageLoader库仍然有些困惑。
I put in onCreate
in my Activity and my adapter : 我在活动和适配器中放入了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);
In my loop (in onPostExecute
) : 在我的循环中(在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);
Then I did also change my adapter of previous (using ImageLoader
class) : 然后,我确实也更改了以前的适配器(使用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;
}
Became (using Universal Image Loader
) on part : 在部分上成为(使用Universal Image Loader
):
try {
String urlImage = obj.getImg();
if(urlImage.length() > 0){
img.setTag(urlImage);
imageLoader.displayImage(urlImage, img);
}
} catch (Exception e) {
}
But after my app run turns still images can not be displayed. 但是在我的应用运行后,静止图像无法显示。 Is there a setting that is lacking in this library? 该库中是否缺少设置? Please help 请帮忙
似乎有点过头了-对于一个使用异步加载并很好地处理列表视图的优秀库,请查看github上的koush (著名的开发人员) UrlImageViewHelper lib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.