gpt4 book ai didi

android - Toast.makeText() 显示错误

转载 作者:行者123 更新时间:2023-11-29 15:24:10 25 4
gpt4 key购买 nike

我正在尝试使用 gps 查找位置,但以下代码 fragment 创建问题。错误显示为

The method makeText(Context, CharSequence, int) in the type Toast is not applicable
for the arguments (GeocodingMainActivity, String, int)

..........

private class MyLocationListener implements LocationListener {

public void onLocationChanged(Location location) {
String format = String.format( "New Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude());
String message = format;
Toast.makeText(GeocodingMainActivity.this, message, Toast.LENGTH_LONG).show();
}

public void onStatusChanged(String s, int i, Bundle b)
{Toast.makeText(GeocodingMainActivity.this, "Provider status changed",Toast.LENGTH_LONG).show();
}

public void onProviderDisabled(String s) {
Toast.makeText(GeocodingMainActivity.this,"Provider disabled by the user. GPS turned off",Toast.LENGTH_LONG).show();
}

public void onProviderEnabled(String s) {
Toast.makeText(GeocodingMainActivity.this,"Provider enabled by the user. GPS turned on",Toast.LENGTH_LONG).show();
}

最佳答案

试试这个...

Toast.makeText(getApplicationContext(), "message", Toast.LENGTH_LONG).show();

关于android - Toast.makeText() 显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14660801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com