我想加载一个文件夹中的所有图像,而无需知道文件的名称,并将其存储到一个整数向量 - 在运行时
I would like to load all images in a folder without knowing the names of the files and store them into a Integer vector - at runtime.
在事实上,我需要的相同,因为它是在本实施例中完成的: http://developer.android.com/resources/tutorials/views/hello -gridview.html 但在运行时和在不知道文件的名称
In fact, i need the same as it is done in this example: http://developer.android.com/resources/tutorials/views/hello-gridview.html But at runtime and without knowing the names of the files.
任何帮助吗?
你的答案后,我知道该怎么做...但我不知道如何用同样的方式去为例:
After your answers i know how to do it... but i dont know how to go on in the same way as the example:
我怎么能保持图像的整数数组,而不是一个可绘制数组或类似的?这是我尝试用绘制:DrawArray [I] = Drawable.createFromPath(fileArray [I] .getPath()); 但我想用整数做到这一点,以适应上述!链接
How could i keep the images in an integer array instead of an drawable array or similar?. Here is my try with drawable: DrawArray[i] = Drawable.createFromPath(fileArray[i].getPath()); But i would like to do it with integer to fit with the link above!
在此先感谢
常规解决方案: HTTP://www.anddev。组织/ viewtopic.php?吨= 575
要获得特定文件夹中的所有文件,使用的 列表()
-method 的文件
级,其中列出指定目录下的所有文件。
To get all files of a specific folder, use the list()
-method of the File
-class, which lists all Files of the specified directory.
要创建位图(然后可以得出),可以使用 BitmapFactory
级。
To create a Bitmap (which can then be drawn), you can use the BitmapFactory
-class.
在这之后,你需要创建自己的适配器(如图所示连接教程),以显示你的位图。
After that, you'll need to create your own Adapter (as shown in the linked tutorial) to show your Bitmaps.