1

我正在尝试在图库视图中显示存储在 SD 卡中的所有图像。

我曾尝试使用内容提供程序(android.provider.MediaStore.images.Media 类),但似乎卡在了某个点上。不确定这是否是解决方法。

到目前为止,这是我的代码:

        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);

只要朝正确的方向轻推,将不胜感激。

4

1 回答 1

2

这篇博客文章有一个很好的例子。它向您展示了如何使用适配器:http : //mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html 但是我将扩展 CursorAdapter 而不是 BaseAdapter。

于 2010-05-25T09:19:59.287 回答