File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes How to retrieve image path from database and put into ImageSwitcher? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to retrieve image path from database and put into ImageSwitcher?" Watch "How to retrieve image path from database and put into ImageSwitcher?" New topic
Author

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

Chin Ginger
Greenhorn

Joined: Mar 31, 2014
Posts: 6
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:

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4174
    
  21

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.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve image path from database and put into ImageSwitcher?