Monday, 19 August 2013

How to add images into grid when GridView scrolled?

How to add images into grid when GridView scrolled?

I have 10k(10000) images want to display into the GridView I am using
below code to get the images from sd card in particular folder.
I have method
public void getFromSdcard() {
File file = new File("/mnt/sdcard/IMG");
if (file.isDirectory()) {
listFile = file.listFiles();
for (int i = 0; i < listFile.length; i++) {
f.add(listFile[i].getAbsolutePath());
}
}
}
and call it to
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
getFromSdcard();
GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
imageAdapter = new ImageAdapter();
imagegrid.setAdapter(imageAdapter);
}
When I have 1k(1000) images the above code works find but not for
10k(10000) images. I got the OutOfMemory error because I am try to get all
the images in one stork.
I am displaying the 9 images into grid at time. So I want to get the
images when grid view scroll. Means first grid display 9 images at the
same time other 9 images loaded into background and display when the
gridview scrolled.
thanks in advance

No comments:

Post a Comment