Forums Register Login

How to retrieve image path from database and put into ImageSwitcher?

+Pie Number of slices to send: Send
I am developing an Android apps which include plenty of image for each attraction place. For example, when user clicks on UK, there should be specific for UK and when clicks on US, there are another images.

Currently I am using ImageSwitcher and hardcode to display the images

If I put the `R.drawable.UK_1,R.drawable.UK_2,R.drawable.UK_3` in the database, how can I put this image path in the final Integer[]? And all these codes are required to done in the AsyncTask since I need to retrieve the data from the database and display it while user clicks on certain attraction place.

Current Code:


Classes:

+Pie Number of slices to send: Send
It looks to me like you are asking how to use the database (build table, insert your rows, query for output). If so, I would suggest you read this section of the Android API Guides: http://developer.android.com/guide/topics/data/data-storage.html. It has a section on SQLite which will have more detail than what we can describe here. Having some understanding of SQL will help as well.

But I am not sure your best option is to put the IDs in the database. The IDs are constant only in a version of your application. Every time you update your app you would need to re-create the data table. Also, do you plan on shipping all densities of all the location images to your users? That sounds like a lot of content to download.

What I would suggest is storing your images in the assets folder, using AssetManager to locate them, and using Bitmap methods to scale appropriately for the device. Then the database would hold the URI paths to the files, which would be constant between app updates (unless you change them) rather than IDs which might not be.
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3187 times.
Similar Threads
How to display Images stored on sdcard?
How to put n intent on a gridview to lauch another activity in android?
Get byte[] of image
calculate ImageView dimentions before user interact the UI
How to add text to gridview
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:48:28.