如何在GalleryView显示从SD卡的图像

如何在GalleryView显示从SD卡的图像

本文介绍了如何在GalleryView显示从SD卡的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示所有存储在SD卡中的一个画廊查看图像。

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

我使用的内容提供商(android.provider.MediaStore.images.Media类)都试过了,但似乎陷入在一个点。不知道这是要走的路吧。

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.

下面是我的code到目前为止:

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

在正确的方向只是轻推将大大AP preciated。

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

推荐答案

本博客文章有一个很好的例子。它显示了你怎么办适配器: HTTP: //mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html 不过,我会被延长一个BaseAdapter的CursorAdapter的替代。

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.htmlHowever I would be extending a CursorAdapter instead of a BaseAdapter.

这篇关于如何在GalleryView显示从SD卡的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:56