Kalu Khan Luhar
Kalu Khan Luhar

Reputation: 1074

How to show images stored on an SD card in an Activity with ViewPager?

I have images on the SD card and I want to show these images in an Activity with a ViewPager.

On horizontal scroll the image should change.

Upvotes: 2

Views: 1391

Answers (2)

Wajdi Hh
Wajdi Hh

Reputation: 785

With this methode you can retrive your picture from SDcard in a drwable object

public Drawable getImageFromSdCard(String imageName) {
    Drawable d = null;
    try {
        String path = Environment.getExternalStorageDirectory().toString()
                + "/YourSubDirectory/";
        Bitmap bitmap = BitmapFactory.decodeFile(path + "/" + imageName
                + ".png");
        d = new BitmapDrawable(bitmap);
    } catch (IllegalArgumentException e) {
        // TODO: handle exception
    }
    return d;

}

and then just call this Drawable in your ViewPager.

G.Luck

Upvotes: 3

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

use this: Retrieving only images from gallery when firing android image chooser intent to get image from gallery.

And use this to show it horizontally: http://developer.android.com/resources/tutorials/views/hello-gallery.html

You need to club both these codes together.

Upvotes: 1

Related Questions