Creating hashmap/map from XML resources

后端 未结 6 1393
礼貌的吻别
礼貌的吻别 2020-12-02 09:56

I\'m making an application where a web service fetches (amongst other) a bunch of codes from a webservice (I.e BEL, FRA, SWE). During runtime I want to translate these codes

6条回答
  •  鱼传尺愫
    2020-12-02 10:35

    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.

提交回复
热议问题