Soni Kumar
Soni Kumar

Reputation: 303

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

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();
    }

Upvotes: 3

Views: 1158

Answers (1)

Sourabh Bans
Sourabh Bans

Reputation: 3134

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.

Upvotes: 4

Related Questions