我有一个扩展 MapActivity 的主类,我将在子类中创建警报对话框,但我遇到了 Context 参数错误。这是我的java代码:
公共类主要扩展 MapActivity {
private MapView mapView;
private MapController mapController;
private GeoPoint geopoint;
public class MapOverlay extends Overlay {
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapv){
if(event.getAction()==1){
GeoPoint p = mapv.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(), "Location: " +
p.getLatitudeE6()/1E6 + "," +
p.getLongitudeE6()/1E6, Toast.LENGTH_LONG).show();
AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("Hello World");
ad.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ad.show();
}
return false;
}
}
}
错误是:
构造函数 AlertDialog.Builder(main.MapOverlay) 未定义!
我将其更改为getBaseContext()
,但遇到强制关闭错误。