本文介绍了将图像资源ID存储在Sqlite数据库中并在int数组中检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线购物应用程序,其中将所有产品详细信息以及产品图像的资源ID存储在Sqlite数据库中.我正在检索那些id(例如:R.drawable.image1),以便显示存储在drawable文件夹中的图像.

I am developing an online shopping app, where I am storing all the product details in Sqlite database, along with resource ids of product images. I am retrieving those ids(eg: R.drawable.image1), in order to display the images, stored in drawable folder.

精确检索了ID,但是发生异常,例如"InvalidNumberFormatException:R.drawable.image1".我已经将所有id作为VARCHAR存储在sqlite中.将这些ID检索为字符串值后,如何将它们存储在int数组中?

The ids are retrieved precisely, but an exception occurs, as "InvalidNumberFormatException: R.drawable.image1". I have stored all the ids, as VARCHAR, in sqlite. How can I store these ids in an int array, after they are retrieved as string values ?

我正在使用recyclerview显示这些图像和其他产品详细信息.任何帮助,将不胜感激.预先感谢.

I am displaying these images and other product details using recyclerview. Any help would be appreciated. Thanks in advance.

推荐答案

只需将图像名称存储在数据库中,并使用以下代码获取其ID

Just store name of image in database and use below code to get its id

private void loadImage(String mImageName, ImageView mImageIcon){
int resID = mContext.getResources().getIdentifier(mImageName , "drawable", mContext.getPackageName());
            if(resID!=0) {//The associated resource identifier. Returns 0 if no such resource was found. (0 is not a valid resource ID.)
                mImageIcon.setImageResource(resID);
            }
}

这篇关于将图像资源ID存储在Sqlite数据库中并在int数组中检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 12:31