我可以个性化 googlemapview 上项目的 onTap() 对话框吗? (我想在上面添加一个按钮)

发布于 2024-10-07 09:09:51 字数 651 浏览 2 评论 0原文

我有一个带有 itemizedoverlays 的地图视图,与 Android 开发人员指南的示例完全相同: http://developer.android.com/resources/tutorials/views/hello-mapview.html

在该示例中,当您按下某个项目时,它会显示一个带有标题和正文的对话框

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;
}

:工作正常,我仍然需要显示该对话框,但我需要添加一个按钮,当我按下它时,它会加载一个新活动,也许还有更多文本行。

我该怎么做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2024-10-14 09:09:51

当然,这是可能的。

我就是这样做的。请注意,还可以使用 setNeutralButton。
据我所知,您可以使用这 3 个按钮。

也看看这个。 Android 开发者上的 AlertDialog

      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();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文