I'm populating a layout from an XML. I don't really understand the tutorial so I can only get TextViews populated. How do I dynamically assign an image resource to the ImageView each list item has?
What I'm currently doing:
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromResource(getApplicationContext(),
R.raw.symbols);
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_SYMBOL);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
map.put(KEY_FILENAME, parser.getValue(e, KEY_FILENAME));
map.put(KEY_ABBR, parser.getValue(e, KEY_ABBR));
map.put(KEY_ELEMENT, parser.getValue(e, KEY_ELEMENT));
// adding HashList to ArrayList
menuItems.add(map);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.symbol_list_item, new String[] { KEY_NAME,
KEY_FILENAME, KEY_ABBR, KEY_ELEMENT }, new int[] {
R.id.name, R.id.filename, R.id.abbr, R.id.element });
setListAdapter(adapter);
And if it matters, I'm not simply setting a drawable for an ImageView. I'm using the custom SVGImageView from the androidSVG library. What I have working on a different activity for dynamically pulling the SVG file is this:
symbolImageView = (SVGImageView) findViewById(R.id.symbolImage);
symbolImageView.setImageResource(this.getResources().getIdentifier(symbol.getFilename(), "raw", this.getPackageName()));
And this is what it looks like currently with my placeholder ImageViews: