如何从谷歌地图警报对话框启动活动

时间:2013-01-09 12:03:48

标签: android google-maps android-activity android-alertdialog

我创建了一个带叠加的地图,我需要当我按下其中一个向我显示一个带按钮的对话框,当我按下按钮开始另一个活动时。我怎么能这样做因为我尝试使用startActivity(意图)但是给我错误。

公共类MiItemizedOverlay扩展了ItemizedOverlay {

public MiItemizedOverlay(Context context, Drawable defaultMarker) {
    super(boundCenterBottom(defaultMarker));
    this.context = context;
}

public void addLocalizacion(double lat, double lon, String etiqueta) {
    int lt = (int) (lat * 1E6);
    int ln = (int) (lon * 1E6);
    punto = new GeoPoint(lt, ln);
    OverlayItem item = new OverlayItem(punto, etiqueta, null);
    mOverlays.add(item);
    populate();
}

public void clear() {
    mOverlays.clear();
    populate();
}

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

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

@Override
protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.setPositiveButton("Go", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(context, OtraActivity.class);
            startActivity(intent);


        }
    }).create().show();
    return true;
}

}

2 个答案:

答案 0 :(得分:2)

使用Context

MiItemizedOverlay class字段
@Override
protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.setPositiveButton("Go", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(context, OtraActivity.class);
            //here
            context.startActivity(intent);
        }
    }).create().show();
    return true;
}

也不要忘记在调用其他活动

之前关闭对话框

答案 1 :(得分:0)

protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.setPositiveButton("Go", new DialogInterface.OnClickListener() {  
        public void onClick(DialogInterface dialog, int id) {
             Intent intent = new Intent(context, OtraActivity.class);
             dialog.cancel();
             context.startActivity(intent); 
        }});
    dialog.show();
    return true;
}