English 中文(简体)
完成活动 - 谷歌地图和机器人
原标题:Finish Activity - Google Maps Android

我为Android做了一个Google地图项目。 我创建了一个地图活动性, 以装入服务器上我保存的一些地方。 所以我有这个类。

public class PlaceItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext = null;
    MapActivity mapAct = null;

    public PlaceItemizedOverlay(Drawable defaultMarker, MapActivity map) {
          super(boundCenterBottom(defaultMarker));
              this.macAct = map;
    }

    public PlaceItemizedOverlay(Drawable defaultMarker, Context context) {
          super(boundCenterBottom(defaultMarker));
          mContext = context;
        }

    @Override
    protected OverlayItem createItem(int i) {
      return mOverlays.get(i);
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }


    @Override
    public int size() {
      return mOverlays.size();
    }

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

     this.mapAct.finish();

      return true;
    }

当我点击一个保存的地方 程序就会中断

我在地图活动上创建对象:

PlaceItemzedOverlay itemizedoverlay = new PlaceItemizedOverlay(drawable, this);

你能帮我一下吗?

非常感谢!

最佳回答

问题就在这里 / / 部分您的代码

  @Override
  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();//here you show a alert dialog on current activity 

  //this.mapAct.finish();//and here you finish current activity

  return true;
}

at this situation application crashes.. and use

finish(); 

用于您的

 this.mapAct.finish();
问题回答

如您所说, 如果您正在创建您的 medicalizatedoverlay 对象, 使用...

PlaceItemzedOverlay itemizedoverlay = new PlaceItemizedOverlay(drawable, this);

...那么下面的线是无效的...

AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);

基本上,您拥有两个 PlaceTroundzedOverlay 的同源符。 第二个参数是 Context ,另一个参数是 Mapactivity 。这些是将 mContext 设置为有效参考的仅有两个地方,两者都是相互排斥的。换句话说,无论使用哪个构建者,“code>mContext mapAct 都将保留null

在您的 onTap 方法中使用 mContext mapAct 方法时混合使用 mContext mapAct 永远不会有效...

AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);

...

this.mapAct.finish();




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签