У меня есть список, что каждая ячейка отображает большое изображение. Я использую универсальную библиотеку андроида для загрузки изображений для загрузки изображений в ImageViews. Я установил хранилище изображений на chace и disk true, но список не прокручивался плавно (я сомневаюсь, что кеш работает правильно). Итак, я создал битмап-массив для хранения загруженных изображений, но теперь у меня проблема с ошибкой «из памяти».Lazy loading image listView
Вот код:
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
socialHolder holder = null;
Object obj = arrayList.get(position);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/big_noodle_titling.ttf");
row = mInflater.inflate(R.layout.social_cell, null);
holder = new socialHolder();
holder.image = (ImageView)row.findViewById(R.id.socialCellImage);
holder.title = (TextView)row.findViewById(R.id.socialCellTitle);
holder.location = (TextView)row.findViewById(R.id.socialCellLocation);
holder.date = (TextView)row.findViewById(R.id.socialCellDate);
final Event ev = (Event)obj;
socialCell social = new socialCell(ev.imageURL,ev.title,ev.date,ev.location.name);
com.nostra13.universalimageloader.core.ImageLoader imageLoader = com.nostra13.universalimageloader.core.ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
holder.title.setText(social.title);
if (!contains(loaded,position)) {
DisplayImageOptions conf = new DisplayImageOptions.Builder().cacheInMemory(false).cacheOnDisc(false).build();
if (social.image != null) imageLoader.displayImage(social.image, holder.image, conf, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view,FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
loadedImage.compress(Bitmap.CompressFormat.JPEG, 100, stream);
ev.realImage = stream.toByteArray();
loadedImages[position] = loadedImage;
loaded[position] = position;
}
});
else {
holder.image.setImageBitmap(loadedImages[position]);
}
PS: Я уже установить cacheInMemory верно и cacheInDisk верно.