从创建的XML资源的HashMap /图资源、XML、HashMap

2023-09-05 07:06:36 作者:脑子一片空白

我在做一个应用程序,Web服务取(其中包括)C $ CS从web服务(即比利时,法国,瑞典)一堆$。在运行时我想这些codeS转化为自己的apporiate的名字显示给用户(即比利时,法国,瑞典)。可以有很多这样的codeS,所以我不知道是否有任何approriate方式来存储(code,名)条目作为某种映射在Android上的XML资源,所以我能够迅速被赋予code取这个名字?

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 to their apporiate names to display to users (I.e Belgium, France, Sweden). There can be a lot of these codes, so i'm wondering if there is any approriate way to store the (code, name) entry as a some sort of map in the XML resources in Android, so I can quickly fetch the name by the given code?

这是所有关于速度在这里,因为地图上可以有几百项。

It's all about speed here, since the map can have a few hundred entries.

推荐答案

今天,我遇到了同样的问题,研究developer.android.com很长一段时间没有帮助,因为Android的资源不能被散列(地图),只阵列。

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.

于是我发现2种方式:

有这样值的字符串数组BEL |比利时,在节目中并存储在一个地图&LT初解析这些字符串;>

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

有2字符串数组:先用美的价值观,以FRA,SWE二为比利时,法国,瑞典

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.