I’m making an app using ORMLite to store datas into the android device.
So basically, I have created a class Question with some attributes, and each question has a specific image related to it.
I was thinking about stock my images in the assets folder and then do something like this
@DatabaseField
private String pathToTheImage;
and then loop for each question:
ImageView iv = (ImageView)view.findViewById(R.id.image);
iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(myQuestion.getpathToTheImage())));
So my question is, is there a better idea to stock png files in android DB ? I couldn’t find a nice tutorial for that.
Thanks,
The
assetsfolder contains only files that you add to your application. You can not write into this folder.If you only store images, that come from your
assetsfolder, than your approach is correct. Otherwise you should usecontext.openFileOutput()to create files inside your app’s private directory, and you can still go with your approach… to keep the path to the files.Another alternative would be to story your images in the
Databaseasblobtype inORMLiteusingDataType.BYTE_ARRAY. You can have a look at this post for more details on doing so.