我無法在位置偵聽器中調用toast.Maketext。上下文不可用,我做錯了什麼?Android toast.makeText上下文錯誤
private LocationListener ll = new LocationListener() {
public void onLocationChanged(Location l) {
// SMSReceiver.l = l;
String s = "";
s += "\tTime: " + l.getTime() + "\n";
s += "\tLatitude: " + l.getLatitude() + "°\n";
s += "\tLongitude: " + l.getLongitude() + "°\n";
s += "\tAccuracy: " + l.getAccuracy() + " metres\n";
s += "\tAltitude: " + l.getAltitude() + " metres\n";
s += "\tSpeed: " + l.getSpeed() + " metres\n";
// TODO Auto-generated method stub
if (l.hasSpeed()) {
mySpeed = l.getSpeed();
}
Log.i(DEBUG_TAG, "On Location Changed: (" + s + ")");
ERROR HERE--> Toast.makeText(context, s, Toast.LENGTH_SHORT).show();
}
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
};
試試這個Toast.makeText (getApplicationContext(),s,Toast.LENGTH_SHORT).show(); – 2011-05-03 09:00:22
我試過,我得到: **方法getApplicationContext()是未定義的類型newLocationListener(){} ** – ProNeticas 2011-05-03 09:04:01
我應該注意,這在** BroadcastReceiver **而不是** Activity ** – ProNeticas 2011-05-03 09:05:35