How to display images from SD card in a GalleryView

佐手、 提交于 2019-12-06 14:48:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2901342/how-to-display-images-from-sd-card-in-a-galleryview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!