我正在寻找执行以下操作的最佳方法。
我有这样的循环...
while(mcursor.moveToNext()){
String tname = mcursor.getString(4);
String tmessage = mcursor.getString(7);
String tlink = mcursor.getString(5);
String tsname = mcursor.getString(3);
Double tlat = mcursor.getDouble(1);
Double tlng = mcursor.getDouble(2);
}
对于循环的每个元素,我想应用以下内容...
GeoPoint point = new GeoPoint(tlat,tlng);
OverlayItem overlayitem = new OverlayItem(point, tname, tmessage);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
我该怎么做?答案可能很明显,但是我很困惑。
最佳答案
像这样
mcursor = getCursor(); //or whatever
if(mcursor != null && mcursor.moveToFirst())
{
do
{
String tname = mcursor.getString(1);
String tmessage = mcursor.getString(2);
String tlink = mcursor.getString(3);
String tsname = mcursor.getString(6);
Double tlat = mcursor.getDouble(2);
Double tlng = mcursor.getDouble(3);
GeoPoint point = new GeoPoint(tlat,tlng);
OverlayItem overlayitem = new OverlayItem(point, tname, tmessage);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}while(mcursor.moveToNext());
}