如何通过读取存储在 android 内部存储器中的所有图像来创建自定义图库

How create Custom gallery by reading all images stored in android internal storage

我正在开发一个 android 应用程序,我在其中将图像保存在指定的文件夹中 editing.Now 我想在我的 activity 中显示所有这些存储的图像。我可以通过指定特定的 name.But 来显示特定的图像 我想一起显示所有图像.. 提前致谢。 我正在使用以下代码显示单个图像......

 File myDir=new File("/sdcard/MyCollection");
    myDir.mkdirs();
    try {
        File f=new File(myDir, "My Image name.jpg");   
        Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
        ImageView img=(ImageView)findViewById(R.id.imageView);
        img.setImageBitmap(b);
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }

如果我回答了你的问题,那么你可以检索带有 .jpg 扩展名 运行 的文件列表,在列表上循环并显示在图像视图中。

    File root = new File("/sdcard/MyCollection");
    final String files[] = root.list(imageFilter);
    FilenameFilter imageFilter = new FilenameFilter() {
        File f;
        public boolean accept(File dir, String name) {
        if(name.endsWith(".jpg")) {
                return true;
            }
            f = new File(dir.getAbsolutePath()+"/"+name);

            return f.isDirectory();
        }
    };  

files 将 return 一个 files.You 的数组可以在其上循环。