【问题标题】:Switch activity from a AlertDialog button从 AlertDialog 按钮切换活动
【发布时间】:2012-09-11 06:51:57
【问题描述】:

我正在开发基于地图的应用程序。比方说,我有三个类: 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 的新手,我希望你们会考虑它。请帮忙 !

【问题讨论】:

    标签: java android google-maps android-alertdialog


    【解决方案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();
    

    【讨论】:

    • 感谢您的回复。我刚刚检查了您的个人资料,发现您提出或回答的所有问题都与谷歌地图有关。好像,您也在开发地图应用程序。 fahim.ahmed1988@gmail.com 是我的邮寄地址。如果您愿意,可以与我联系。在联系人上拥有地图极客对我来说非常棒。不管怎么说,还是要谢谢你 。 :-)
    • 欢迎您!:) 当然,为什么不呢。 :) 如果您需要地图方面的帮助,您可以联系我,否则我会联系您。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 2018-07-08
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多