So I have seen many resources online and it's usually about using blob type to store my image in SQLite database table in android studio but I actually tried that out and was not sure how to do it.
I actually came across the concept of getting the path of the image and storing as resource id and then calling it in my main activity
This is what I have seen in terms of retrieving it (I am developing a quiz app and I need to retrieve the stored image in the database and display as an ImageView like my question.)
Is there any way someone can let me know how I can store the image in SQLite table in android studio and then retrieving it as such. I am aware that getImage()
is the getter that will be declared in which the resource will be stored in that possibly the SQLite put command that is usually done to insert values using content values
photoQuestion = (ImageView) findViewById(R.id.photoquestion);
photoQuestion.setImageResource(PHOTO_QUESTION.getImage());
My code to insert data into the table, so far for my question (which is supposed to be the image) i have been testing it as string to be able to display and see if it is working but now i want to replace the first field of the table to image (from current string to image datatype instead)
private void fillQuestions() {
PeopleModeQuestions question1 = new PeopleModeQuestions("photo of john", "Father", "Mother", 1);
addQuestions(question1); // question will be inserted in database everytime this method is called
PeopleModeQuestions question2 = new PeopleModeQuestions("photo of mary", "Father", "Mother", 2);
addQuestions(question2);
PeopleModeQuestions question3 = new PeopleModeQuestions("photo of susan", "Sister", "Friend", 1);
addQuestions(question3);
PeopleModeQuestions question4 = new PeopleModeQuestions("photo of mark", "Sister", "Friend", 2);
addQuestions(question4);
}
private void addQuestions(PeopleModeQuestions questions) {
ContentValues values = new ContentValues();
// using the getter method, get questions out of the object
values.put(PeopleModeConstants.MemoryDementiaQuestions.MemoryDementia_Relatives_Column_Photo, questions.getPhoto());
values.put(PeopleModeConstants.MemoryDementiaQuestions.MemoryDementia_Relatives_Column_Relationship1, questions.getRelationship1());
values.put(PeopleModeConstants.MemoryDementiaQuestions.MemoryDementia_Relatives_Column_Relationship2, questions.getRelationship2());
values.put(PeopleModeConstants.MemoryDementiaQuestions.MemoryDementia_Relatives_Column_CorrectRelationship, questions.getCorrectRelationship());
db.insert(PeopleModeConstants.MemoryDementiaQuestions.MemoryDementia_Relatives_Table, null, values);
}