Question

I am working on an app and one of my activities is a screen that grabs all the images in a folder I made in the /data/ application folder. I would like to to grab all the photos lay them out in a grid format and then when a person clicks on one it blows it up to full size. Of course this gallery needs to change when new images are added to the folder.

Seems like it would be some thing simple to do but I am having some trouble implementing this I keep finding a lot of different solutions non of which seem quite right.

I'm assuming it would be some sort of gridview/listadapter combination.

What would the best solution to this problem?

EDIT

I have looked into these solutions http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ http://developer.android.com/guide/topics/ui/layout/gridview.html#example

but my confusion is code like this

private Integer[] mThumbIds = {
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_5,
        R.drawable.sample_6, R.drawable.sample_7
};

What do I do about this since the amount of images will be constantly changing in my app folder. And how do I load the images out of that folder in the first place haha

Was it helpful?

Solution

Have you seen the the Caching Bitmaps in Android Developers site? I think it does something similar to what you want. It also provides the code of the example.

You should better store you images in a path inside the sd card, since they need to change dynamically. Then to get the image paths from that path, use something like this (asssuming that you only have images in that directory):

File imagesDir = new File(Environment.getExternalStorageDirectory(), "yourpath");
for (File f : yourDir.listFiles()) {
   if (f.isFile())
      String image_path = f.getPath();
      // make something with the name
}

Also, to load a bitmap from a file in your sd, use something like this:

Bitmap b = BitmapFactory.decodeFile("your_image_path");

Just keep in mind to load a downscaled version of the bitmap for memory efficiency. See here for more information.

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top