1

I want my program to be able to list all the 50 images that are in a local directory and access them at run time. I have tried to store them under the res folder, such as in Drawable, but have found out, according to one source, Ivan Memruk (here) that you can't refer to res folder subfolders by their folder names, because the folder names are all ignored -- you have to just use unique names for all your images and then refer to them by that name and using the whole R and resource id thing.

Also, according to that same article by Ivan, you can use subfolders under the assets folder, but then you can only access the images in them using an input stream, and (apparently) that is not of much use for accessing images.

Whoo, well all that said, does anyone have any other thoughts on an easy way to list all the images in a folder? I don't want to use the SD card by the way as my images will be shipped with the application.

Thanks in advance and thanks to the people who answered before I updated my question.

Tom Panek
  • 105
  • 1
  • 7

2 Answers2

0

Store the images in drawables folder. But maintaining their identifiers (R.drawable) is a problem. You can get the identifiers anytime from :

 getResources().getIdentifier(imageName,"drawable", context.getPackageName());

This will return R.drawable value of image.

The advantage of storing images in drawable folder is you can store resolution specific and orientation specific images.

Sadeshkumar Periyasamy
  • 4,848
  • 1
  • 26
  • 31
0

You may use the assets folder for this purpose, remember not to name the images folder within assets as images, otherwise some extra images will come up in the image list when asked for. Instead try to give a unique name like app_images, etc.

DDas
  • 306
  • 3
  • 12
  • Thanks Deepanjan, but have you tried this? This guy, [Ivan Memruk] (href="http://www.wiseandroid.com/post/2010/06/14/Android-Beginners-Intro-to-Resources-and-Assets.aspx") makes it sound like it won't work easily because you have to do it with an input stream (which I don't understand well). If you have used it for images, can you provide or point me to any code? Thanks. – Tom Panek Mar 29 '12 at 18:23
  • Hey Tom, sorry for the late reply. Follow the links to get an idea of what I am trying to mean: http://stackoverflow.com/questions/4038597/null-pointer-issue-displaying-an-image-from-assets-folder-android-2-2-sdk http://stackoverflow.com/questions/4038597/null-pointer-issue-displaying-an-image-from-assets-folder-android-2-2-sdk Both the links are not an exact solution to your problem but will give you a pointer how to get the images as List from a directory under assets folder. – DDas Apr 18 '12 at 04:09