Search code examples
androidimagepathdirectoryhorizontalscrollview

HorizontalScrollView Getting Images from /drawable folder


I am using HorizontalScrollView in order to create some Gallery-like option and right now I am getting the images from an folder in the external drive. But I figured that I don't need, also shouldn't do that since the images I wanted to show is predetermined images. So I will simply change the directory to the drawable folder but I am not sure which path to go. So right now I am getting the directory with this: String path1= Environment.getExternalStorageDirectory().getAbsolutePath();

I found two more methods for directory retrieval but I am not sure which one to use.

String path2 = Environment.getDataDirectory().getAbsolutePath();

String path3= Environment.getRootDirectory().getAbsolutePath();

First one returns "/mnt/sdcard", second returns "/data", third one "/system".

Which one should I use in order to reach /drawable folder inside this way?


Solution

  • Which one should I use in order to reach /drawable folder inside this way?

    None of them. Those are all for files on the filesystem. Drawable resources are not files on the filesystem.

    Use getResources().getDrawable() to retrieve a Drawable given its ID (e.g., R.drawable.foo).