Alex Rivera | Logout

Android - MapView contained within a Listview

Asked 2010-06-02T20:15:42.933
11

Currently I am trying to place a MapView within a ListView. Has anyone had any success with this? Is it even possible? Here is my code:

            ListView myList = (ListView) findViewById(android.R.id.list);
        List<Map<String, Object>> groupData = new ArrayList<Map<String, Object>>();

        Map<String, Object> curGroupMap = new HashMap<String, Object>();
        groupData.add(curGroupMap);
        curGroupMap.put("ICON", R.drawable.back_icon);
        curGroupMap.put("NAME","Go Back");
        curGroupMap.put("VALUE","By clicking here");

        Iterator it = data.entrySet().iterator();
        while (it.hasNext()) 
        {
            //Get the key name and value for it
            Map.Entry pair = (Map.Entry)it.next();
            String keyName = (String) pair.getKey();
            String value = pair.getValue().toString();

            if (value != null)
            {
                //Add the parents -- aka main categories
                curGroupMap = new HashMap<String, Object>();
                groupData.add(curGroupMap);

                //Push the correct Icon
                if (keyName.equalsIgnoreCase("Phone"))
                    curGroupMap.put("ICON", R.drawable.phone_icon);
                else if (keyName.equalsIgnoreCase("Housing"))
                    curGroupMap.put("ICON", R.drawable.house_icon);
                else if (keyName.equalsIgnoreCase("Website"))
                    curGroupMap.put("ICON", R.drawable.web_icon);
                else if (keyName.equalsIgnoreCase("Area Snapshot"))
                    curGroupMap.put("ICON", R.drawable.camera_icon);
                else if (keyName.equalsIgnoreCase("Overview"))
                    curGroupMap.put("ICON", R.drawable.overview_icon);  
                else if (keyName.equalsIgnoreCase("Location"))
                    curGroupMap.put("ICON", R.drawable.map_icon);
                else
                    curGroupMa
Edit
Report

1 Answer

6

First off, I'm don't think displaying multiple MapViews at once will work. MapActivity documents that only one is supported per process:

"Only one MapActivity is supported per process. Multiple MapActivities running simultaneously are likely to interfere in unexpected and undesired ways."

(http://code.google.com/android/add-ons/google-apis/reference/index.html)

It doesn't explicitly say you can't have multiple MapViews within a MapActivity but I think they'll interfere as well, regardless of what kind of parent ViewGroup they're in.

Second, you might consider using the static maps API to get a simple image for inclusion in the ListView -- a fully-fledged MapView may be unnecessarily heavyweight in any case:

http://code.google.com/apis/maps/documentation/staticmaps/

The one issue you may potentially face is that the Static Maps API limits usage by "user", which probably means by IP (it doesn't require an API key), and mobile networks can be problematic with IP usage limiting. I'm not sure exactly how that'll play out.

answered 2010-06-02T23:51:27.097

Your Answer