0

I need to implement the following functionality: download an image from the internet, and add it as a drawable to resources.

I will also need to get a list of all drawables programmatically when app starts. I can get a drawable from resources by it's id, but the list of drawables will be dynamic, so I will not have the IDs of the drawables.

If someone has a solution for this, help would be greatly appreciated.

Galy Addy
  • 27
  • 6

1 Answers1

0

download an image from the internet, and add it as a drawable to resources.

That is not possible. Resources are read-only at runtime. You are welcome to download the image to internal storage and use it from there.

I will also need to get a list of all drawables programmatically when app starts

For the ones you download to internal storage, use standard Java file I/O to list the files in your chosen directory (e.g., listFiles() on the File pointing to that directory).

For any actual drawable resources that you want to look up dynamically, that's not really recommended. That being said, you can hack in some reflection to make it work.

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491