views:

151

answers:

1

Hi All,

I want to create a java.util.map in android from a resource. I want to do this because I have a lot of entries to populate into the java.util.map and I want to store the values in the res folder of the project in xml format.

Is there an effecient way to do this in android? My map will have around 2500 entries so I want to do this as effeciently as possible and I don't want to hard code them...

Thanks, Gaz

A: 

I think the Xml format is "too much" to simply store key-value pairs. A text file where a line is a key-value pair is more adequat (e.g. with comma separator), also the parsing will be easier.

foo1,bar1
foo2,bar2
...
  • Save your text file in res/raw directory
  • Open it via context.getResources.openRawResource(R.raw.fileName)
  • Loop on each lines and split the line to retrieve the key and the value.
  • Put them in your map

That's all

kosokund
ok, cool, just thought there might be a built in way to do it, like using ArrayAdapter with Arrays in xml format
Gaz
arrays in xml format ? Not sure to understand what are you talking about.
kosokund