androidandroid-mapview

Can I personalize the onTap() dialog of the items on my googlemapview?? (I want to add a button on it)


I have a mapview, with itemizedoverlays, exactly like in the example of Android Developer's guide: http://developer.android.com/resources/tutorials/views/hello-mapview.html

At that example, when you press on a item, it's showed a dialog with a title and a body:

protected boolean onTap(int index) {
  OverlayItem item = mOverlays.get(index);
  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
  dialog.setTitle(item.getTitle());
  dialog.setMessage(item.getSnippet());
  dialog.show();
  return true;
}

It works fine, and I still need to show that dialog, but I need to add A BUTTON, that when I press it it loads a new activity, and maybe some more text lines.

How can I do it?


Solution

  • Sure, that's possible.

    This is how I do it. Do note that there's also a setNeutralButton possible.
    That's 3 buttons you can use as far as I know.

    Look at this as well. AlertDialog on Android Developers

          AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setMessage(item.getSnippet())
                   .setTitle(item.getTitle())
                   .setCancelable(true)
                   .setPositiveButton("View Details", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           Intent intent = new Intent(mContext, org.gpsagenda.DetailsContainer.class);
                           intent.putExtra("id", item.ID());
                           intent.putExtra("isConnected", MainMap.getIsConnected());
                           mContext.startActivity(intent);
                       }
                   })
                   .setNegativeButton("Close window", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           dialog.dismiss();
                       }
                   });
            AlertDialog alert = builder.create();
            alert.show();