Java 从AlertDialog按钮切换活动
我正在开发一个基于地图的应用程序。比如说,我有三个类:MapsActivity、MyItemizedOverlay和GetDirectionActivity。在MyItemizeOverlay中,我想在单击肯定对话框按钮后切换到GetDirectionActivity。ActiveDialog被放置在onTap方法下,这样我就可以得到地质点。为此,我所做的: 在ItemizeOverlay类中:Java 从AlertDialog按钮切换活动,java,android,google-maps,android-alertdialog,Java,Android,Google Maps,Android Alertdialog,我正在开发一个基于地图的应用程序。比如说,我有三个类:MapsActivity、MyItemizedOverlay和GetDirectionActivity。在MyItemizeOverlay中,我想在单击肯定对话框按钮后切换到GetDirectionActivity。ActiveDialog被放置在onTap方法下,这样我就可以得到地质点。为此,我所做的: 在ItemizeOverlay类中: @Override public boolean onTap(GeoPoint p, MapView
@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 ;
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
return super.onTap(p, mapView); }
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();
}
这里IDE显示我在startActivity(intent)行中有一个错误。
我也试过:
在MyItemizeOverlay类中:
@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 ;
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
return super.onTap(p, mapView); }
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();
}
在MapsActivity类中:
@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 ;
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
return super.onTap(p, mapView); }
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,则会显示alertdialog,而不点击地图。
我知道这很愚蠢,但是因为我在Android和java都是新手,希望你们能考虑一下。请帮忙 在ItemizeOverlay类中的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();
谢谢你的回复。我刚刚查看了你的个人资料,发现你所问或回答的所有问题都与谷歌地图有关。看起来,您正在开发一个地图应用程序。法希姆。ahmed1988@gmail.com这是我的通讯地址。如果你愿意,可以和我联系。在联系人上有一个地图极客对我来说太棒了。无论如何,谢谢。:-)欢迎!:)当然,为什么不呢如果您需要地图方面的帮助,可以与我联系,否则我会与您联系。:)