我想在每次用户更改位置时通知用户。我已在onLocationChanged
内插入吐司,但makeText
上的toast.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()
到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());
}}
}
答案 0 :(得分:0)
我很确定在类扩展Activity时可以使用getApplicationContext和getBaseContext。
是否可以扩展Activity并实现MyLocationOverlay?
答案 1 :(得分:0)
特定方法需要扩展Activity,然后才能实现getApplicationContect。