Mapview Balloons To A Detailview
Solution 1:
I am also use this link, http://www.codemobiles.com/forum/code-mobile-topic-4180.html some codes are added,
MyMap.java class
publicclassMyMapextendsMapActivity {
MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
MyItemizedOverlay itemizedOverlay;
//MyItemizedOverlay itemizedOverlay2;@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
// first overlay
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = newMyItemizedOverlay(drawable, mapView);
GeoPointpoint=newGeoPoint((int) (51.5174723 * 1E6),
(int) (-0.0899537 * 1E6));
OverlayItemoverlayItem=newOverlayItem(point, "Umar Shafique",
"(here goes 1)");
itemizedOverlay.addOverlay(overlayItem);
GeoPointpoint2=newGeoPoint((int) (51.515259 * 1E6),
(int) (-0.086623 * 1E6));
OverlayItemoverlayItem2=newOverlayItem(point2, "Abdul Karim",
"here goes 2");
itemizedOverlay.addOverlay(overlayItem2);
mapOverlays.add(itemizedOverlay);
// second overlay/* drawable2 = getResources().getDrawable(R.drawable.marker2);
itemizedOverlay2 = new MyItemizedOverlay(drawable2, mapView);
GeoPoint point3 = new GeoPoint((int) (51.513329 * 1E6),
(int) (-0.08896 * 1E6));
OverlayItem overlayItem3 = new OverlayItem(point3, "Arslan Ilyas",
"here goes 3");
itemizedOverlay2.addOverlay(overlayItem3);
GeoPoint point4 = new GeoPoint((int) (51.51738 * 1E6),
(int) (-0.08186 * 1E6));
OverlayItem overlayItem4 = new OverlayItem(point4, "Ahsan",
"here goes 4");
itemizedOverlay2.addOverlay(overlayItem4);
mapOverlays.add(itemizedOverlay2);*/finalMapControllermc= mapView.getController();
mc.animateTo(point2);
mc.setZoom(16);
}
@OverrideprotectedbooleanisRouteDisplayed() {
returnfalse;
}
}
Here I comment some code, because here add two itemizedOverlay , so one is comment.
and MyItemizedOverlay.java class
publicclassMyItemizedOverlayextendsBalloonItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;
publicMyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}
publicvoidaddOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
publicintsize() {
return m_overlays.size();
}
@Override
protected boolean onBalloonTap(int index) {
Toast.makeText(c, "onBalloonTap for overlay index " + index,
Toast.LENGTH_LONG).show();
if (index == 0) {
c.startActivity(new Intent(c.getApplicationContext(),
NewActivity.class));
} else {
c.startActivity(new Intent(c.getApplicationContext(),
secondNewActivity.class));
}
returntrue;
}
}
Here modification code
if (index == 0) {
c.startActivity(newIntent(c.getApplicationContext(),
NewActivity.class));
} else {
c.startActivity(newIntent(c.getApplicationContext(),
secondNewActivity.class));
}
returntrue;
}
press balloon two , we can change index position. we can pass index position through your intent.
provide your code , that only Easy the Explain.
Solution 2:
In the Itemized Overlay onClick handler, add an intentExtra so you can pass identifying information to your QuoteDetail.class. More than likely you'll want to extend the ItemizedOverlay class with your own class, add member variable(s) that you can use to identify the item. Then simply access these member variables and pass them to QuoteDetail as intentExtras.
Post a Comment for "Mapview Balloons To A Detailview"