【发布时间】:2010-06-02 20:15:42
【问题描述】:
目前我正在尝试在 ListView 中放置一个 MapView。有没有人在这方面取得任何成功?甚至可能吗?这是我的代码:
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
curGroupMap.put("ICON", R.drawable.icon);
//Pop on the Name and Value
curGroupMap.put("NAME", keyName);
curGroupMap.put("VALUE", value);
}
}
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");
//Set up adapter
mAdapter = new SimpleAdapter(
mContext,
groupData,
R.layout.exp_list_parent,
new String[] { "ICON", "NAME", "VALUE" },
new int[] { R.id.photoAlbumImg, R.id.rowText1, R.id.rowText2 }
);
myList.setAdapter(mAdapter); //Bind the adapter to the list
提前感谢您的帮助!!
【问题讨论】:
-
好吧,我咬一口。为什么 ListView 中需要 MapView?
-
另外,您遇到了什么问题?
-
假设 -- 您列出了特定业务的所有内容..我想显示它在列表中的位置的地图。我遇到的问题是我不知道从哪里开始。我想将它包含在 ListView 中,而不必启动一个全新的 Intent (这违背了 listview 的目的)。
-
嘿 Ryan,你在 listAdapter 中显示 mapview 完成了吗?我也在尝试实现这样的功能。
标签: android listview android-mapview