获取SD卡上位图的ID
我的应用程序有一个部分,其中一些图像显示在网格视图中。
在设置 gridview 之前,请完成以下操作:
- 从 Internet 下载图像文件名列表
- 将此列表与 Drawable 文件夹中已存在的项目进行比较
- 如果图像不存在于 Drawable 文件夹中,则下载该图像并将其保存到SD 卡。
设置 gridview 时,我通过使用可绘制 ID 来实现,这些 ID 很容易获取,因为它们位于资源文件夹(“可绘制”)中。
但是如果我需要在 gridview 中包含 SD 卡图像,我该如何检索它们的 ID?
My app has a section where some images are displayed in a gridview.
Before the gridview is set up, the following is done:
- Download list of image file names from the internet
- Compare this list to items already present in the Drawable folder
- If the image is not present in the Drawable folder, download it and save it to the SD card.
When setting up the gridview I do it by using the drawable IDs, which are easy to get as they are in a resource folder ("drawable").
But if I need to include the SD card images as well in the gridview, how can I retrive their IDs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了与应用程序一起打包的文件(例如下载到内部或外部存储)之外的任何位置的文件都没有资源 ID。
资源 ID 是引用打包资源(例如字符串、图像等)的简写方式。这些 id 是在构建时创建的,仅对内部资源有意义。
为了使用从外部源获取的图像,您可以通过文件名访问它们,我想,您将创建
ImageViews
并将其添加到您的GridView
中。如果您需要区分网格的不同图像(可能是出于触摸/单击目的),那么您需要处理的是 ImageView,而不是关心它们所包含的图像的资源 ID 或文件名。
Files anywhere other than those packaged with your app (downloaded to the internal or external storage, for instance) don't have resource ids.
Resource ids are a shorthand way of referencing the packaged resources such as strings, images, whatever. These ids are created at build-time and only have meaning for internal resources.
In order to use images obtained from an external source, you access them by filename and, I presume, you'll then create
ImageViews
which are added to yourGridView
.If you need to discern between the different images of the grid (perhaps for touch/click purposes) then it's the
ImageView
that you deal with rather than being concerned with resource ids or filenames of the images they contain.我有一个代码从 sdcard 获取图像并将它们转换为 URI 数组,id 就像 URI,使用它们。
您可以像这样使用 uri:-
I was having a code to get images from sdcard and convert them into an array of URIs, the ids are like URIs, use them.
You can use the uri like this:-