0
我想將緯度和經度的值返回到我的EditText
s,我已經能夠使用Toast
來做到這一點,但沒有通過EditText
實現。好心幫Android TextBox
// EditText latEditText = (EditText)findViewById(R.id.lat);
//EditText lngEditText = (EditText)findViewById(R.id.lng);
protected void showCurrentLocation(){
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null){
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(LayActivity.this, message,
Toast.LENGTH_LONG).show();
//latEditText.setText(nf.format(location.getLatitude()).toString());
//lngEditText.setText(nf.format(location.getLongitude()).toString());
}
}
private class MyLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(LayActivity.this, message, Toast.LENGTH_LONG).show();
//latEditText.setText((int) location.getLatitude());
//lngEditText.setText((int) location.getLongitude());
}
可能想解釋它的工作原理;也就是說,因爲向'setText'提供一個'int'就意味着它是一個資源ID。 – Eric