I've just begun learning to create Android apps, and I'm struggling with what seems like a very elementary problem.
I'm trying to create a HashMap which is loaded from an XML. However, I'm unable to figure out what the resource ID for a Map stored this way would be. I've used the solution to this problem: Creating hashmap/map from XML resources .
The issue I'm facing is how exactly to structure the res folder and how to reference my data in that res folder.
Here's what I currently have:
Resource Parser1:
public class ResourceUtils {
public static Map<String,String> getHashMapResource(Context c, int hashMapResId) {
Map<String,String> map = null;
XmlResourceParser parser = c.getResources().getXml(hashMapResId);
String key = null, value = null;
...
}
return map;
}
}
My res/xml/map.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<map name = "testMap" linked="true">
<entry key="key1">value1</entry>
<entry key="key2">value2</entry>
<entry key="key3">value3</entry>
</map>
So to get hold of the Map, I need to correctly enter the resource ID into my call to getHashMapResource, but I can't find how to do that! I've tried:
R.string.map
R.map.testMap
R.xml.map
R.xml.testMap
I'm out of ideas. I'm sure the problem is trivial to someone who knows this, but I couldn't find anything helpful around the place. Thanks :)