开发者

populating galleryview with images from sqlite DB dynamically

I have a sqlite database that has over 2000 low res thumbnails of pictures. The database itself is over 100MB in size. The project requires me to have the photos residing in the database instead of the file path.

This is what I would like to do and need help with as this is my first time dealing with images. I have a horizontal GalleryView in my App UI that I want to populate with images pulled from this database dynamically. I don't mind if these images are lazy loaded on to the gallery view in the background. I read somewhere that I will have to use an ImageAdapter to bind the images to the开发者_如何学运维 UI element dynamically. I need in understanding how this is done. I have never used the BaseAdapter class.

Thanks, AB


You will indeed be subclassing an Adapter to pull the images out of your db turn them into Bitmaps or Drawables then set your picture to an ImageView and add it to your Gallery.

I would suggest you switch away from using a Gallery right now before you get going though. Gallery has a bug where it will not allow your Adapter to recycle views properly. This means while the user is scrolling the gallery every time a new Image enters the screen a new ImageView object is getting created. This is wasteful and will lead to noticeable performance drop while your gallery is being scrolled due to garbage collection constantly running.

To get started with your adapter check out SimpleCursorAdapter and search around online for examples of how to extend SimpleCursorAdapter. Inside your getView method you'll pull your image out of the db and set it into a view to be shown to the user.


I was able to do this using a custom adapter and a string array that holds the location of the images on the sdcard. Before doing all this though, I have to pull images from the database and copy them over to an sdcard location. I am working on avoiding this step as it adds up 5-7 secs to just copy those images over.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜