1

i would like to know if there is a way to create a hashmap in the android resources and pull it inside the code with getResource()... ?

I am looking to get something similar to python dictionary referenced by key:value. The important part is that i need it to be static inside the resources package

Thanks

Eyal Israel
  • 257
  • 4
  • 9

1 Answers1

0

Android resources cannot be hashes only arrays. You can either create json file in assets and parse it to map or use TypedArray.

Check this out Creating hashmap/map from XML resources

Lakshmi
  • 78
  • 11
  • thanks, i saw that post and it is not what i am looking for. the approach in that example is exactly what i am trying to avoid. i don't want to have multiple string arrays and build a hashmap out from referencing them. That's the entire idea of a map. I want to have the map static in a resource file and pull it inside the code and that's it. – Eyal Israel Jun 21 '18 at 09:06
  • Did you check the third answer by vokilam! @2Dee I'm not able add comment thats why have added it as answer! – Lakshmi Jun 21 '18 at 09:29
  • @imhskal i don't know how to store json in the resources, i believe this may be a good start for me but not a 100% perfect. do you have an example for me? – Eyal Israel Jun 21 '18 at 09:37
  • For project created in Android Studio you need to create assets folder under the main folder. Then you can add the json file to it. check this link https://stackoverflow.com/questions/13814503/reading-a-json-file-in-android/13814551#13814551 – Lakshmi Jun 21 '18 at 09:41
  • *I'm not able add comment thats why have added it as answer* => please don't do that, this limitation is by design. – 2Dee Jun 21 '18 at 10:14
  • I have added the answer as well with the link! – Lakshmi Jun 21 '18 at 10:26