2010-05-25 42 views
1

我试图在库视图中显示存储在SD卡中的所有图像。如何在GalleryView中显示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); 

在正确的方向只是微调,将不胜感激。

回答

2

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

+0

谢谢,这是一个很好的链接。我所关注的书也扩展了BaseAdapter,但我希望能找到一个与之相关的游标相关的方法......更直接的方式。我想这是做到这一点的最佳方式。 – OceanBlue 2010-05-25 22:46:52

+0

你碰巧知道扩展CursorAdapter的一个好例子吗?我尝试过但不能得到它。 – OceanBlue 2010-05-26 00:15:38

+0

经过反思,并与CursorAdapter做了一些工作后,我认为如果实施得当,两者都应该做好这项工作。我只推荐CursorAdapter,因为你可以直接操作游标,无论如何CursorAdapter扩展了BaseAdapter,所以你应该没问题。网络中没有好的例子。到目前为止最好的是看SimpleCursorAdapter(http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/SimpleCursorAdapter.java)。只有你需要重写的方法应该是bindView和newView。 – 2010-05-26 08:52:16

相关问题