I've got a common use-case wherein a user selects one item out of many (say, on a spinner or autocomplete list), then enters the data. For example, let's say the user selects a country. Ultimately, the data I want is the country code, not the country name; but the users will want to select based on name, not code. To put it another way, user's will select "United States", but I ultimately want that to translate into "US".
There are a lot of countries. Is there an easy way to setup a mapping in Android to hash from the name to the code? I've thought of a few solutions, none of them are quite satisfactory in my mind:
A database containing country/code, which I can query on.
Setting up all countries as strings in
strings.xml
, then retrieving the resource by name.Creating a huge Map in code and using that. (This is the least satisfactory answer).
Anyone have any cleverer solutions?