2010-05-25 84 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

相關問題