Android 在图库视图中显示特定文件夹中的图像 [英] Android Display Images From Specific Folder in Gallery View

查看:24
本文介绍了Android 在图库视图中显示特定文件夹中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个小应用程序,该应用程序仅在图库视图中显示来自特定文件夹的图像.我找到了几个例子,但每个例子都只显示了 1 张图像.我将在下面发布的这个示例是一个很好的帮助,它几乎完全符合我的要求,我只需要更改它即可显示特定文件夹中的图像,而不是所有文件夹.我已经进行了几天的尝试,但我似乎没有添加正确的代码.我觉得这是我也很想念的一件非常简单的事情.任何帮助将不胜感激!

I'm trying to make a little app that displays only images from a specific folder in a gallery view. I have found a few examples, but every single one just ends up displaying only 1 image. This example I will post below was a WONDERFUL help, it does almost exactly what I want it to do, I just need to change it to display images from the specific folder, and not all folders. I've given this a few days worth of attempts, but I just don't seem to be adding in the right code. I feel like its a very simple thing that I am missing too. Any help would be greatly appreciated!

public class AndroidCustomGallery extends Activity {

    private int count;
    private Bitmap[] thumbnails;
    private boolean[] thumbnailsselection;
    private String[] arrPath;
    private ImageAdapter imageAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };

                final String orderBy = MediaStore.Images.Media._ID;

                Cursor  imagecursor = getContentResolver().query(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,        
                        null, orderBy);




                int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);          
                this.count = imagecursor.getCount();        
                this.thumbnails = new Bitmap[this.count];       
                this.arrPath = new String[this.count];  
                this.thumbnailsselection = new boolean[this.count];

                for (int i = 0; i < this.count; i++) {

                    imagecursor.moveToPosition(i);

                    int id = imagecursor.getInt(image_column_index);        
                    int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); 

                  thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(        
                            getApplicationContext().getContentResolver(), id,       
                            MediaStore.Images.Thumbnails.MICRO_KIND, null);     

                    arrPath[i]= imagecursor.getString(dataColumnIndex);

                }

                GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);      
                imageAdapter = new ImageAdapter();      
                imagegrid.setAdapter(imageAdapter);     
                imagecursor.close();

推荐答案

想通了!以下是任何想要做类似事情的人粘贴的代码.

Figured it out! Below is the pasted code for anyone who wants to do something similar.

Cursor imagecursor = getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        columns, 
                        MediaStore.Images.Media.DATA + " like ? ",
                        new String[] {"%/yourfoldername/%"},  
                        null);

这篇关于Android 在图库视图中显示特定文件夹中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆