• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

How can I list only folders with images in a gridview?

Search This thread

nex7er

Senior Member
Feb 3, 2008
449
163
Bergen
I can't seem to do this. No tutorials or examples, and the library "Image Loader" (not universal image loader) is not well-enough documentet for someone that is new. I just want to see folders on /sdcard/ with .jpgs and such in them... but all examples of gridview only work with /res/ folder in the app itself.

Any help would be appreciated. I've been trying for days and I'm getting bummed, which is why I turned to asking for help. :/
 

ssuukk

Senior Member
I can't seem to do this. No tutorials or examples, and the library "Image Loader" (not universal image loader) is not well-enough documentet for someone that is new. I just want to see folders on /sdcard/ with .jpgs and such in them... but all examples of gridview only work with /res/ folder in the app itself.

Any help would be appreciated. I've been trying for days and I'm getting bummed, which is why I turned to asking for help. :/

1) Create adapter that will create the exact view you want.

Here all you have to do is to is to create in getView a layout with ImageView, load your image using

Bitmap toDisplay = BitmapFactory.decodeFile(path_to_your_image_file)

and then supply the bitmap to your ImageView. The tricky part is that Views get recycled (= when the view disappears offscreen it will be supplied to your adapter's getView(...) method via converView argument), so if your bitmap gets decoded after the particular part of GridView went offscreen, it will appear in most unexpected place...

2) attach the adapter to grid view (it does accept adapter, right? I don't know, because I've never used it...)

Done :D

But since you will probably want to create your bitmaps asynchronically you will have to go through the pain of protecting yourself against putting Bitmap in recycled view... It requires some thinking.