Android的显示图像从特定文件夹中的图片查看 [英] Android Display Images From Specific Folder in Gallery View

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

问题描述

我试图让一个小应用程序,在画廊视图显示特定文件夹中的映像。我已经找到了几个例子,但是每一个人刚刚结束了只显示1图像。这个例子我会后下面是一个奇妙的帮助下,它几乎完全是我想要它做的事,我只需要改变它从特定的文件夹显示图像,而不是所有的文件夹。我给了值得尝试的这几天,但我似乎没有在正确的code被添加。我觉得它的,我很想念过一个很简单的事情。任何帮助将大大AP preciated!

 公共类AndroidCustomGallery延伸活动{

    私人诠释计数;
    私人位图[]的缩略图;
    私人布尔[] thumbnailsselection;
    私有String [] arrPath;
    私人ImageAdapter imageAdapter;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        最终的String []列= {MediaStore.Images.Media.DATA,MediaStore.Images.Media._ID};

                最后弦乐排序依据= MediaStore.Images.Media._ID;

                光标imagecursor = getContentResolver()查询(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,列,空,
                        空,排序依据);




                INT image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
                this.count = imagecursor.getCount();
                this.thumbnails =新的位图[this.count]
                this.arrPath =新的String [this.count]
                this.thumbnailsselection =新的布尔[this.count]

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

                    imagecursor.moveToPosition(ⅰ);

                    INT ID = imagecursor.getInt(image_column_index);
                    INT dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);

                  缩略图[I] = MediaStore.Images.Thumbnails.getThumbnail(
                            getApplicationContext()。getContentResolver(),身份证,
                            MediaStore.Images.Thumbnails.MICRO_KIND,NULL);

                    arrPath [I] = imagecursor.getString(da​​taColumnIndex);

                }

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

解决方案

想通了!下面是粘贴code的人谁愿意做类似的事情。

 光标imagecursor = getContentResolver()查询(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        列,
                        MediaStore.Images.Media.DATA +怎么样?,
                        新的String [] {%/ yourfoldername /%},
                        空值);
 

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天全站免登陆