0

我正在开发基于地图的应用程序。假设,我有三个类: MapsActivity 、 MyItemizedOverlay 和 GetDirectionActivity 。在 MyItemizedOverlay 中,我想在单击肯定对话框按钮后切换到 GetDirectionActivity。ActiveDialog 放在 onTap 方法下,这样我就可以得到 GeoPoint。为此,我做了什么: 在 ItemizedOverlay 类中:

@Override
public boolean onTap(GeoPoint p, MapView mapView) {
    // TODO Auto-generated method stub
    int lat = p.getLatitudeE6();
    int lot = p.getLongitudeE6();
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setTitle("Confirmation");
    dialog.setMessage("Confirm this as end point ?");
    dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int arg1) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(mContext, GetDestination.class);
            startActivity(intent);
        }
    });
    dialog.setNegativeButton("No", null);
    dialog.show();
    return true ; 
            }

这里 IDE 显示我在 startActivity(intent) 行中有错误。我也试过了:在 MyItemizedOverlay 类中:

@Override
public boolean onTap(GeoPoint p, MapView mapView) {
            return super.onTap(p, mapView); }

在 MapsActivity 类中:

GeoPoint point2 = null ;
            confirmationOverlay.onTap(point2, mapView) ;
            int latt = point.getLatitudeE6() ;
            int longt = point.getLongitudeE6();
            final int endpointArray [] = {latt , longt};
            if(some condition to show the alert dialog after tapping)
            {
                AlertDialog.Builder dialog = new AlertDialog.Builder(MapsActivity.this);
                dialog.setTitle("Confirmation");
                dialog.setMessage("Confirm this location as end point ?");
                dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int arg1) {
                        // TODO Auto-generated method stub
                        Intent intent = new Intent(MapsActivity.this,GetDestination.class);
                        intent.putExtra("geopoint" , endpointArray);
                        startActivity(intent);
                    }
                });
                dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int arg1) {

                    }
                });
                dialog.show();
            } 

对于 if 语句,我可以使用什么样的条件?如果我将其设置为 lat>0,则无需点击地图就会出现警报对话框。我知道这很愚蠢,但是由于我是 android 和 java 的新手,我希望你们会考虑它。请帮忙 !

4

1 回答 1

1

在 ItemizedOverlay 类中的 OnTap 方法上:

AlertDialog dialog = new AlertDialog.Builder(MapsActivity.context).create();
           dialog.setTitle("Confirmation");
           dialog.setMessage("Confirm this location as end point ?");

     dialog.setButton(DialogInterface.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

     Intent intent = new Intent(MapsActivity.context, GetDestination.class);
                        //you must put your map activity    
                            MapsActivity.context.startActivity(intent);


                        }   
                    });


              dialog.show();
于 2012-09-10T22:51:57.363 回答