【问题标题】:Android How can I load every images from the drawable folder using file to set into the imageItems?Android 如何使用文件从可绘制文件夹加载每个图像以设置为 imageItems?
【发布时间】:2015-06-01 07:10:23
【问题描述】:

当我不知道图像文件名时,如何从可绘制文件夹加载图像。

我想在 gridview 中显示所有可绘制的文件夹图像。

我只知道如何从文件名加载图像,如下所示:

 // 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;
     }

但是现在如果我不知道文件名(R.drawable.filename),我如何使用文件从可绘制文件夹加载每个图像以设置到 imageItems 中?

非常感谢。

【问题讨论】:

标签: android file bitmap drawable bitmapfactory


【解决方案1】:
Field[] drawables = android.R.drawable.class.getFields();
for (Field f : drawables) {
    try {
        Log.i("LOG", "R.drawable." + f.getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

试试这个

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    相关资源
    最近更新 更多