1

Im trying to get value of Hashmap array but im getting index/key.

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

Code how i get values from parser

 HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
map.put(KEY_LAT, parser.getValue(e, KEY_LAT));
map.put(KEY_LON, parser.getValue(e, KEY_LON));
map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
menuItems.add(map);

Then i try get values but i receive index.

for (int i = 0; i < menuItems.size(); i++){
        int latitude = Integer.parseInt(KEY_LAT);
        int longitude = Integer.parseInt(KEY_LON);
        itemizedOverlay.addOverlayItem(latitude, longitude, KEY_NAME, makerDefault);
    }

How to get value from menuItems array ? In other activity i get values but there is used through TextView. Is there other way ?

2 Answers 2

4

Try this:

for (Map<String, String> menuItem : menuItems) {
    int latitude = Integer.parseInt(menuItem.get(KEY_LAT));
    int longitude = Integer.parseInt(menuItem.get(KEY_LON));
    itemizedOverlay.addOverlayItem(latitude, longitude, KEY_NAME, makerDefault);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Iterating through the Array is best done like this:

for (HashMap map: menuItems) {
}

then you can access the map itself:

for (HashMap map: menuItems) {
    String value = map.get(key);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.