Creating hashmap/map from XML resources

Today I came across the same problem and studying developer.android.com for a long time didn’t help since Android resources cannot be hashes (maps), only arrays.

So I found 2 ways:

  1. Have a string array of values like “BEL|Belgium”, parse those string early in the program and store in a Map<>

  2. Have 2 string arrays: first with the values of “BEL”, “FRA”, “SWE” and second with “Belgium”, “France”, “Sweden”.

Second is more sensitive cause you have to synchronize changes and order in both arrays simultaneously.

Leave a Comment