首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ItemizedOverlay类开始活动

从ItemizedOverlay类开始活动
EN

Stack Overflow用户
提问于 2011-01-02 11:58:38
回答 3查看 2.5K关注 0票数 1

我正在尝试获取一个将ItemizedOverlay扩展到startActivity的类,但是有一个问题,它就是不能编译。我有一个使用ItemizedOverlay类绘制覆盖图的MapView,但我想要在点击屏幕时启动和活动。

你知道怎么解决这个问题吗?谢谢

代码语言:javascript
复制
protected boolean onTap(int index) {
     OverlayItem item = overlays.get(index);

     String split_items = item.getSnippet();
     Intent intent = new Intent();
     intent.setClass(mainmenu,poiview.class);
     startActivity(intent);


     return true;
   }
EN

回答 3

Stack Overflow用户

发布于 2011-07-07 01:23:22

我遇到了这个问题,所以我测试了下面的例子。该解决方案依赖于从MapActivity上下文调用"startActivity“。

如果您的地图实际上正在处理覆盖,那么您已经将MapView上下文传递给了自定义ItemizedOverlay构造函数,并且可能将MapView上下文分配给了一个名为mContext的类变量(我假设您遵循了谷歌的MapView示例)。因此,在自定义Overlay的onTap函数中,执行以下操作:

代码语言:javascript
复制
        @Override
    protected boolean onTap(int index) {

      Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
      mContext.startActivity(intent);


      return true;
    }   

但是,您可能希望将某些内容传递给您正在尝试启动的新活动,以便您的新活动可以对您的选择执行一些有用的操作。所以..。

代码语言:javascript
复制
    @Override
protected boolean onTap(int index) {

  OverlayItem item = mOverlays.get(index);
  //assumption: you decided to store an "id" in the snippet so you can associate this map location with your new Activity
  long id = Long.parseLong(item.getSnippet()); //Snippet is a built-in String property of an Overlay object.  

    //pass an "id" to the class so you can query
    Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
    String action = Intent.ACTION_PICK; //You can substitute with any action that is relevant to the class you are calling
    //I create a URI this way because I append the id to the end of the URI (lookup the NotePad example for help because there are many ways to build a URI)
    Uri uri = ContentUris.withAppendedId(Your_CONTENT_URI, id);
    //set the action and data for this Intent
    intent.setAction(action);
    intent.setData(uri);
    //call the class
    mContext.startActivity(intent);  

  return true;
}
票数 5
EN

Stack Overflow用户

发布于 2012-04-19 16:50:05

试试这个,我已经在警告对话框中设置了一个肯定按钮...

代码语言:javascript
复制
protected boolean onTap(int index)  {
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setIcon(R.drawable.info_icon);
dialog.setPositiveButton("Details", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
    Intent placeDetailsMapIntent = new Intent(mContext, PlaceDetailsActivity.class);
    mContext.startActivity(placeDetailsMapIntent);
         }

});

票数 0
EN

Stack Overflow用户

发布于 2011-01-02 13:12:52

试着使用下面的

代码语言:javascript
复制
Intent intent = new Intent(mainmenu.this, poview.class);
startActivity(intent);
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4577043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档