tags:

views:

176

answers:

1

I am trying to display all the images stored in SD card in a Gallery View.

I have tried using the content provider (android.provider.MediaStore.images.Media class), but seem to be getting stuck at a point. Not sure if this is the way to go about it.

Here is my code so far:

        String[] colsNeeded = new String[]{Media._ID, Media.TITLE};
    Uri mMedia = Media.EXTERNAL_CONTENT_URI;

    //Create a cursor using the URI & column names needd
    Cursor c = managedQuery(mMedia, colsNeeded, null, null, Media.DATE_TAKEN + " ASC");

    //What kind of adapter should I create here 
    //that contains images from the cursor?? 
    SpinnerAdapter sa = null; //This is the point I get stuck

    //Set the adapter of the gallery view
    Gallery galleryPetPhotos = (Gallery)findViewById(R.id.GalleryPetPhotos);
    galleryPetPhotos.setAdapter(sa);

Just a nudge in the right direction would be greatly appreciated.

+2  A: 

This blog post has a good example on that. It shows you how to do the adapter: http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html However I would be extending a CursorAdapter instead of a BaseAdapter.

janfsd
Thanks, it is a great link. The book I am following also extends BaseAdapter, but I was hoping to find a cursor related way of doing it... something more straight forward. I guess this is the best way to do it then.
OceanBlue
Do you happen to know a good example of extending the CursorAdapter? I tried it but cannot get it.
OceanBlue
After rethinking about it, and doing some work with CursorAdapter, I think that both should do the work if well implemented. I was only recommending the CursorAdapter since you can directly manipulate a cursor, anyway CursorAdapter extends BaseAdapter so you should be fine. There aren't good examples in the net. The best so far is looking at the SimpleCursorAdapter (http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/SimpleCursorAdapter.java). THe only methods you need to override should be bindView and newView.
janfsd
Thanks for the answer.
OceanBlue
You are welcome ;)
janfsd
I found a better example here: http://code.google.com/p/shelves/source/browse/trunk/Shelves/src/org/curiouscreature/android/shelves/activity/BooksAdapter.java?r=19
janfsd