0

ユーザーが場所を変更するたびにユーザーに通知したいと思います。の中にトーストを挿入しましたが、 fromonLocationChangedにレッドラインがあります。それは言うmakeTexttoast.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()。それでも同じ答えです。クラス名に変更しても同じです

public class CurrentLocationOverlay extends 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());


    }}

  }
4

2 に答える 2

0

クラスがActivityを拡張している場合、getApplicationContextとgetBaseContextを使用できると確信しています。

Activity を拡張して MyLocationOverlay を実装することは可能ですか?

于 2013-04-07T16:45:31.957 に答える
0

特定のメソッドはアクティビティを拡張する必要があり、その後 getApplicationContect を実装できます。

于 2014-11-16T20:44:53.757 に答える