Search code examples
javaandroidsurfaceviewtilesdrawbitmap

Displaying all images from a resource folder


I have a folder in my resource folder called "tiles'. I want to be able to add or remove tiles as I develop this game, which could hold hundreds. Therefore - for the map editor I am making - I want a simple way to load these into an array (the names, at least) and then display them into an appropriate view (surface?) at runtime. Preferably in grid format, i.e. 3 across and then infinite vertically based on a for loop or whatever.


Solution

  • To list the files on a folder, you can use this and it will return an array of File object.

    File dir = new File(Environment.getExternalStorageDirectory() + "/your/directory/on/sdcard/");
    File[] files = dir.listFiles();