How can I load image from drawable folder when I don't know image file name.
当我不知道图像文件名时,如何从可绘制文件夹加载图像。
I want to show all the drawable folder image in the gridview.
我想在gridview中显示所有可绘制的文件夹图像。
I just know how to load the Image from file name, like below:
我只知道如何从文件名加载图像,如下所示:
// ImageItem method :public ImageItem(Bitmap imageBitmap, String title){...}
private ArrayList<ImageItem> getData()
{
final ArrayList<ImageItem> imageItems = new ArrayList<>();
TypedArray imgs = mContext.getResources().obtainTypedArray(R.array.image_ids);
for( int i = 0 ; i< imgs.length(); i++ )
{
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), imgs.getResourceId(i, -1));
imageItems.add(new ImageItem(bitmap, "Image#" + i));
}
return imageItems;
}
But now if I don't know file name(R.drawable.filename), How can I load every images from the drawable folder using file to set into the imageItems?
但是现在如果我不知道文件名(R.drawable.filename),如何使用文件将可绘制文件夹中的每个图像加载到imageItems?
Thank you very much.
非常感谢你。
1 个解决方案
#1
0
Field[] drawables = android.R.drawable.class.getFields();
for (Field f : drawables) {
try {
Log.i("LOG", "R.drawable." + f.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
try this
#1
0
Field[] drawables = android.R.drawable.class.getFields();
for (Field f : drawables) {
try {
Log.i("LOG", "R.drawable." + f.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
try this