每当用户更改位置时,我想通知用户。我在onLocationChanged
中插入了吐司,但是toast.makeText
上的makeText
上有一条红线。它说
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (CurrentLocationOverlay, String, int)
然后我从
Toast.makeText(this,"Your current speed is :" +gps.getSpeed, Toast.LENGTH_SHORT).show()
to Toast.makeText(getBaseContext(),"Your current speed is :" +gps.getSpeed, Toast.LENGTH_SHORT).show().
然后它告诉我创建getBaseContext()
方法。我甚至把它改成了getApplicationContext()
。还是一样的答案。甚至把它改成了类名还是一样的
公共类CurrentLocationOverlay扩展MyLocationOverlay {
GPSTracker gps;
@Override
public synchronized void onLocationChanged(Location location) {
super.onLocationChanged(location);
Toast.makeText(this,"Your current speed is :" +gps.getSpeed(),
Toast.LENGTH_SHORT).show();
// only move to new position if enabled and we are in an border-area
if (mc != null && centerOnCurrentLocation && inZoomActiveArea(currentPoint)) {
mc.animateTo(getMyLocation());
}}
}
我很确定getApplicationContext和getBaseContext可以在类扩展Activity时使用。
是否有可能扩展Activity并实现MyLocationOverlay?
特定的方法需要扩展Activity,然后才能实现getApplicationContect