Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:12:32+00:00 2026-05-26T06:12:32+00:00

i have a listview that displays images from a directory and it is loading

  • 0

i have a listview that displays images from a directory and it is loading the images fine but then when scrolling in order to scroll up after scrolling down i have to remove my finger from the screen and place it back on the screen to scroll back up. also if scroll is too fast application crashes with logcat saying OutOfMemoryError.

here is my code:

package com.search.visual;


import java.io.File;
import java.io.FilenameFilter;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;


public class history extends ListActivity{

private String dir = ".vis";
private File images;
private File [] imageList;
private File item;
private Uri [] ImageRef;
private ImageView imageView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.history);




    loadPics();



}



public class ImageAdapter extends BaseAdapter {
    int Background;
    private Context con;



    public ImageAdapter(Context c) {
        con = c;
        TypedArray attr = con.obtainStyledAttributes(R.styleable.HelloGallery);
        Background = attr.getResourceId(
                R.styleable.HelloGallery_android_galleryItemBackground, 0);
        attr.recycle();
    }

    public int getCount() {
        return ImageRef.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

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



        imageView = new ImageView(con);
        imageView.setImageURI(ImageRef[position]);
        imageView.setLayoutParams(new ListView.LayoutParams(75, 75));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);

        imageView.setBackgroundResource(Background);

        return imageView;
    }


}

 protected void onListItemClick(ListView l, View v, int position, long id) {

     item = imageList[position];
     Intent i = new Intent("com.search.visual.IMAGE");

        i.putExtra(Intent.EXTRA_STREAM, item);
        startActivity(i);           //StIntring imname = (String) ;
   }





@Override
protected void onResume() {
    // TODO Auto-generated method stub
    loadPics();
    super.onResume();
}

public void loadPics(){

    images = Environment.getExternalStoragePublicDirectory(dir);
    imageList = images.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String filename) {
            // TODO Auto-generated method stub
            return (filename.endsWith(".jpg"));
        }
    });

    if(imageList.length > 0 ){
    ImageRef = new Uri[imageList.length];

    for(int i = 0; i<imageList.length; i++){
        ImageRef[i] = Uri.parse(imageList[i].getAbsolutePath());

    }

    setListAdapter(new ImageAdapter(this));
    }else{
        Intent i = new Intent("com.search.visual.ERROR");
        startActivity(i);
    }
}


}

if anyone one has any clue as to why this is happening your help would be greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:12:32+00:00Added an answer on May 26, 2026 at 6:12 am

    When you scroll the listview all the images are stored in native heap and the recycler of native heap is too lazy. So it is slow in collect garbage from the scrolled images from listview and that’s why your device's heap is become full and you get the OutOfMemory Exception.

    So I think you sholud try your own recycler for garbage the images in application and free the memory of used images.

    you have to recycle bitmap. The bitmap implementation is native, so the java object is small and a poor candidate for java garbage collection but the memory is still allocated. Taka a look to Bitmap.recycle()

    or else just try to Lazzy Loading images in Listview.

    Android: Strange out of memory issue and OutOfMemory exception appears while scrolling the list of images

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView on a page that displays a list of widgets. When
I have a ListView that I am populating with items from an ObservableCollection .
In one of my Activities I have a ListView that displays a list of
I have a list of images that are pulled from a database and loaded
I have a bunch of large 400x400 images that I am pulling from a
I have this ListView that displays a custom user control. The custom user control
I have a ListView that displays every item in an array called, Facts_Array. What
I have created a list view that displays the names and dates of items
I have a ListView where I would like to display things horizontally. That works
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.