I am trying to work out if I can use a resource file, while developing my android app, to hold a list of numbers using a string value as a key. For example
numbers(“UK”)= 999
numbers(“US”) = 911
As I said, this would ideally be in resource file rather than a Java class as it is more maintainable
You want to define a dictionary in resources. There’s no way to do that directly. You could however define the keys and values as arrays, then build the dictionary.
In
res/values/arrays.xml, have something like,Then in your code you have this utility method,
When you need the dictionary in your code, do this,