My application will find the users around myself and shown it on the map.
I can add the overlayItem on the mapView but how can I add some caption for the image for example the user name.
After I clicked the item, a dialog box is shown.
Can I set a listener that can invoke a new activity when the user clicked the box? My intention is somehow I can go to the user profile by the overlayItem. Is it possible to do so? Thanks
i have found the solution and wanted to share for ppl who is interested. As i cannot answer to my own question, i will edit the question.
For added caption for the overlayItem:
@Override
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
{
super.draw(canvas, mapView, shadow);
if (shadow == false)
{
//cycle through all overlays
for (int index = 0; index < mOverlays.size(); index++)
{
OverlayItem item = mOverlays.get(index);
// Converts lat/lng-Point to coordinates on the screen
GeoPoint point = item.getPoint();
Point ptScreenCoord = new Point() ;
mapView.getProjection().toPixels(point, ptScreenCoord);
//Paint
Paint paint = new Paint();
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(mTextSize);
paint.setARGB(150, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
//show text to the right of the icon
canvas.drawText(item.getTitle(), ptScreenCoord.x, ptScreenCoord.y+mTextSize, paint);
}
}
}
For starting a new activity in the dialog box you need to override the onTap method in the ItemizedOverlay class:
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage("Are you sure you want to see this user's profile?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent();
i = new Intent(mContext,
ViewFdProfile.class);
mContext.startActivity(i);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
}
Hope this help, cheers!