Is there a way to get all the icons inside the drawable folder? Im looking for a way similar to how one would get all files from a folder on a SD card, like:
ArrayList<File> file = new ArrayList<File>();
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"directoryName");
With that snipped you get all files inside a folder called directoryName which is located inside the phones pictures folder.
So i was hoping for something like this:
Drawable[] d = getResources().getDrawables() //But this way you could only get one drawable through its id
All the files in the assets folder can be accessed so easily so why note drawables:
String[] files = null;
AssetManager assetManager = getActivity().getAssets();
try {
files = assetManager.list("BookFrames");
} catch (IOException e) {
e.printStackTrace();
}
I could store the pictures in the assets folder and get all of them with the above snippet, however, i was hoping to create an additional res folder where i would store all my image buttons, and other pictures that i use in my app. The advantage of this is that i could store pictures with different resolutions, and hopefully android would return the correct sized image for a certain screen resolution.
The current scenario. I am creating a custom adapter which includes pictures of book covers, and to prevent the pictures looking tiny on certain screens i would need to include many resolutions of the covers. And by using the drawable directory i let android take care of which resolutions to display, there fore i need a way to get all the drawables as a list when populating my adapter (hoping that android would choose the appropriate picture resolution for me).
I saw this tread How to display list of resource drawables which show a method to do this, but with that method it would get all the pictures (i dont think android will choose the appropriate resulution with that method, it will just collect all pictures).
Imagine making a memory game where each card is a picture, to make that look good on different screens you need many resolutions for those pictures. So placing those pictures inside drawable would let the android engine take care of the choosing. And you would not need code to check users screen size. But maybe its better to use the below and check the screen resolution of the used than choose appropriate asset folder?
assets/pictures/xhdpi/frame1
hdpi/frame1