0

I am developing an application in android and I have a folder of images and need to load and show them in my app using Gridview(something like android gallery). for this task I used this library.

Now my question is where is the best place to put this folder of images in application package(i.e in res or assets folder or etc) and how can I get its path in runtime?

P.S. I know about Drawable directory but I need sth other than this, e.g. I want to put my images in res/raw but how can I get raw directory path in runtime?

Alireza
  • 1,018
  • 1
  • 8
  • 23

3 Answers3

0

Just place your all images in res/drawable folder Now if you to use image, say you want to set it on the image view, Simply write:

<imageView
android:width="wrap_content"
android:height="wrap_content"
android:src="@drawable/image_name"/>

or programmatically:

imageview.setImageResource(R.drawable.image_name);
Er.Rohit Sharma
  • 696
  • 5
  • 21
0

A bitmap file is a .png, .jpg, or .gif file. Android creates a Drawable resource for any of these files when you save them in the res/drawable/ directory.

Documentation

In the code you can get them using R.drawable.file_name

Kirill Feoktistov
  • 1,448
  • 24
  • 28
  • I know about Drawable directory but I need sth other than this, I want to put a folder of images in res, and get its absolute path in runtime – Alireza Sep 29 '15 at 13:17
0

Finally I found the solution. The best way to store a folder of images, make a sub-folder under Assets folder then you can get its file names in run-time using the following command:

getAssets().list("sub-folder")

and get the stream of each file using:

getAssets().open("sub-folder/file-name")
Alireza
  • 1,018
  • 1
  • 8
  • 23