Android Question image in database (pls chk my psu code)

Beja

Expert
Licensed User
Longtime User
Hi all,
Searching the forum I didn't find a database example with image column, the image is the same in all columns, say "1.png", but some rows (records) have it while others don't.. so I am doing it
like the following pseudo-code:

1- If a check box, next to imageview1 is checked (true), then imageview1 is loaded with 1.png
and the number "1" will be saved in a hidden column in the database
otherwise imageview1 is loaded with "" and the number "0" will be saved in the same hidden column in the database.

2- When browsing the database, the logical state of the hidden field will be evaluated and if true then 1.png will be loaded to imageview1, otherwise "" will be loaded.

I feel this is not a good coding practice, so please point me to a better code.

Thanks in advance.
 

mangojack

Expert
Licensed User
Longtime User
@ Edit .. Beja I have just reread your post and maybe misunderstood that you were going to store image in DB but have decided on a different approach . I will leave this post anyway.
I don't believe there is anything wrong with your current approach.

Beja .. my first thought is , If it is the same image ' 1.png ' stored in the DB , why bother.
I have a similar app. There are 2 images in DirAssets ... ' 1.png ' and ' noimage.png ' ( some sort of image that reflects no image or no data present)
If the hidden column in your DB contains 1 then load ' 1.png ' else load the other image from Assets.

If you are still interested in storing the image in your db I have included a very basic example that will insert an Assets image to a DB then retrieve that image and display in a ImageView.
 

Attachments

  • ImageDB Example.zip
    56 KB · Views: 203
Last edited:
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi mangojack,

Thanks for your efforts..
You are right, I don't want to store images in db.. in fact the image is a signature field and I don't want to fill the db with the same image
May be will use a checkbox or something and then use it as a condition to load the image.. But really I don't know the best optimized code for this.
 
Upvote 0
Top