0

I have some image files which will be dynamically loaded in my app. I know I can put images in the "/res/drawable" directory, but can there be somewhere else I can put files and loaded them by file name at runtime?

The image files contain characters that are now allowed in resource names. I did not name them, so ideally, I need to keep the names. For example, suppose I have "Cat #1.png" and "Cat #2.png", and I would like to load the image into an ImageView by that name at runtime, like so:

MyImageView1.setImageBitmap(createBitmapFromContentDirectory("Cat Pictures/Cat #2.png"))
MyImageView2.setImageBitmap(createBitmapFromContentDirectory("Dog Pictures/Dog #1.png"))

Is that possible, or should I change all image names into conforming names (e.g., cat_number1.png and cat_number2.png) and put them into the drawable directory?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • 3
    are you aware of assets directory? – SAIR Dec 18 '17 at 13:13
  • I might have, but I did not remember it when posting this. Thank you for the hint. I think 'assets' is the correct solution. https://stackoverflow.com/questions/18302603/where-do-i-place-the-assets-folder-in-android-studio – Damn Vegetables Dec 18 '17 at 13:20

1 Answers1

0

You can put them in assets & load them from there, Otherwise you can also put them in raw folder. you can refer to Where do I I Place assets folder for assets.assets doesn't create Resource Id, so you can access them directly. Have a look at this difference between assets & raw.

Ganesh
  • 368
  • 5
  • 15