将存储在手机/存储卡中的图库图像导入recyclerview [英] import gallery images which are stored in phone/memory card into recyclerview

查看:185
本文介绍了将存储在手机/存储卡中的图库图像导入recyclerview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从列表中选择要上传的图片时,我正试图从图库图像中填充recyclerview,因为Instagram会导入图库图像。我想实现类似的东西。有关如何访问手机/存储卡上的图库图像并填充Recyclerview 的任何建议。另外,请建议以任何方式实现Instagram界面选择要上传的图像

I am trying to populate recyclerview from gallery images as instagram imports gallery images while you select images from the list to upload. I want to implement similar type of thing. Any suggestions on how to access the gallery images on phone/memory card and populate the recyclerview. Also please do suggest any way to implement instagram like interface for selecting images to upload.

推荐答案

你可以使用Android媒体商店来挑选图片,视频和音频

you can use Android media store to pick pictures,Videos and Audios

图片的示例代码:

    private void imageMediaQuery() {
    String[] projection = new String[]{
            MediaStore.MediaColumns.DATA,
            //MediaStore.Images.Media._ID,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
            MediaStore.Images.Media.DATE_TAKEN
    };

    Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    String BUCKET_GROUP_BY =
            "1) GROUP BY 1,(1";
    String BUCKET_ORDER_BY = MediaStore.Images.Media.DATE_TAKEN + " DESC";

    Cursor cur = this.getContentResolver().query(images,
            projection, // Which columns to return
            BUCKET_GROUP_BY,       // Which rows to return (all rows)
            null,       // Selection arguments (none)
            BUCKET_ORDER_BY        // Ordering
    );

    if(cur!=null){
        Log.i("ListingImages", " query count=" + cur.getCount());
    }


    if (cur!=null&&cur.moveToFirst()) {
        String bucket;
        String path;
        int bucketColumn = cur.getColumnIndex(
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME);

        int pathColumn = cur.getColumnIndex(
                MediaStore.MediaColumns.DATA);

        do {
            bucket = cur.getString(bucketColumn);
            path = cur.getString(pathColumn);

        } while (cur.moveToNext());
        cur.close();

    }
}

在上面的代码中你得到了路径对于每个图像,只需在recyclelerview适配器的onBindViewHolder中使用该路径来显示images.hope,这会有所帮助。

In the above code you get path for each image and simply use that path in your onBindViewHolder of recyclerview adapter to display images.hope this helps.

这篇关于将存储在手机/存储卡中的图库图像导入recyclerview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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