3

I am developing an android app in which i am saving images in a specified folder after some editing.Now i want to show all these stored images in my activity. I m able to show a particular image by specifying a particular name.But i want to show all images together.. Thank in advance. I m using Following code to show single image......

 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();
    }
Somasundaram NP
  • 1,018
  • 1
  • 12
  • 36
Soni Kumar
  • 283
  • 1
  • 4
  • 16

1 Answers1

4

if i follow your question, than you can retrieve the list of file with .jpg extension run a loop on list and show in imageview.

    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 will return an array of files.You can loop on it.

SRB Bans
  • 3,096
  • 1
  • 10
  • 21
  • if it works and you think it useful...you can accept it as a answer. – SRB Bans Sep 19 '15 at 07:34
  • Further, You can use `gridView` to show a Matrix of image thumbnails just like a gallery – Adeel Ahmad Sep 19 '15 at 08:20
  • that is the way of dealing to show the images... that can be achieved with simple listview also... that depends on requirement of app... – SRB Bans Sep 19 '15 at 08:24
  • i think that this is better : if(name.toLowerCase().endsWith(".jpg") || name.toLowerCase().endsWith(".png")) { return true; } – abbasalim Dec 28 '16 at 09:49