如何在Android中的图库中加载RecyclerView中的图像和视频?

时间:2016-01-09 06:45:51

标签: android gallery android-recyclerview

我正在尝试从图库中将图片,视频和屏幕截图加载到RecyclerView。单击RecyclerView项时需要使用listselector突出显示并需要获取所选路径的列表。可以任何人建议这样做。如下图所示:

enter image description here

1 个答案:

答案 0 :(得分:1)

对于多个图像选择器,请点击此链接    DroidNinja Filepicker

制作适配器和POJO类以在RecycelrView上查看所选照片

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case FilePickerConst.REQUEST_CODE_PHOTO:
            if (resultCode == Activity.RESULT_OK && data != null) {
                filePaths.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_PHOTOS));
                Image img;
                ArrayList<Image> images = new ArrayList<>();
                try {
                    for (String path : filePaths) {
                        img = new Image();
                        img.setUri(Uri.fromFile(new File(path)));
                        Log.e("VIDEO", Uri.fromFile(new File(path)) + "");
                        images.add(img);
                    }
                    rvPhoto.setAdapter(new MyAdapter(this, images));
                } catch (Exception e) {
                    e.printStackTrace();

                }
            }
            break;
           }