gpt4 book ai didi

java - 从 AlertDialog 按钮切换 Activity

转载 作者:行者123 更新时间:2023-12-01 15:11:02 36 4
gpt4 key购买 nike

我正在开发一个基于 map 的应用程序。比方说,我有三个类: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,则无需点击 map 即可出现警报对话框。我知道这很愚蠢,但由于我是 android 和 java 的新手,我希望你们能考虑一下。请帮忙 !

最佳答案

在 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();

关于java - 从 AlertDialog 按钮切换 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12359827/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com